home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / mc220.zip / MC.DOC < prev    next >
Text File  |  1992-02-24  |  165KB  |  3,403 lines

  1.           
  2.           
  3.           
  4.           
  5.           
  6.           
  7.           
  8.           
  9.           
  10.           
  11.           
  12.           
  13.           ===========================================================
  14.           MM   MM  IIIIIII    CCCC   RRRRRR     OOO             CCCC
  15.           M M M M     I      C    C  R     R   O   O           C    C
  16.           M  M  M     I     C        R     R  O     O         C
  17.           M     M     I     C        RRRRRR   O     O  -----  C
  18.           M     M     I     C        R   R    O     O         C
  19.           M     M     I      C    C  R    R    O   O           C    C
  20.           M     M  IIIIIII    CCCC   R     R    OOO             CCCC
  21.           ===========================================================
  22.     
  23.     
  24.     
  25.     
  26.     
  27.                              A compact 'C' compiler
  28.                                for small systems.
  29.     
  30.     
  31.                                 Technical Manual
  32.     
  33.     
  34.     
  35.     
  36.     
  37.                                   Release 2.2
  38.     
  39.                                Revised 17-Feb-92
  40.     
  41.     
  42.     
  43.     
  44.     
  45.     
  46.     
  47.     
  48.     
  49.     
  50.     
  51.     
  52.     
  53.     
  54.     
  55.                        Copyright 1988,1992 Dave Dunfield
  56.                               All rights reserved
  57.     MICRO-C                                                          Page: 1
  58.  
  59.  
  60.     1. INTRODUCTION
  61.     
  62.           MICRO-C is a compact, portable compiler for a subset  of  the  'C'
  63.        language which is suitable for implementation on small 8  or  16  bit
  64.        computer systems. It may be used as a resident or cross compiler, and
  65.        is capable of generating ROMable code. It is  distributed  in  source
  66.        form, and thus provides a learning tool for those wishing to  examine
  67.        the internals of a working compiler.
  68.     
  69.           The main goal in the development of MICRO-C, has been to provide a
  70.        reasonably powerful language  which  will  be  portable  with  little
  71.        difficulty to many  target  systems.  The  'C'  language  was  chosen
  72.        because  it  was  designed  to  be  portable,  and   provides   ample
  73.        programming power. MICRO-C provides  an  alternative  to  interpreted
  74.        BASIC or assembly language  programming  which  are  often  the  only
  75.        languages available on small 8 bit systems.
  76.     
  77.           With today's focus on larger computers and workstations,  software
  78.        support for small  systems  and  micro-controller  sized  devices  is
  79.        getting hard to find. MICRO-C helps fill that gap, because all  files
  80.        necessary to port and maintain  the  compiler  are  included  on  the
  81.        distribution disks, allowing it to be moved  to  ANY  system  without
  82.        dependance on a software vendor.
  83.     
  84.           Sample code generators  and  runtime  librarys  are  included  for
  85.        several popular microprocessors.
  86.     
  87.           Also included with the compiler is the 'C' and 'ASM'  source  code
  88.        for a complete library of system  functions,  as  well  many  example
  89.        programs.
  90.     
  91.           The MICRO-C "package" (software and documentation) is copyrighted,
  92.        and may  not  be  re-distributed  in  any  form  without  my  written
  93.        permission. If you have received the  "DEMO"  archive,  and  wish  to
  94.        obtain the entire MICRO-C package complete with source code, fill out
  95.        and send the order form contained in the "READ.ME" file,  along  with
  96.        the required payment to:
  97.     
  98.                            Dunfield Development Systems
  99.                            P.O. Box 31044
  100.                            Nepean, Ontario (Canada)
  101.                            K2B 8S8
  102.     
  103.           Please make your cheque  or  money  order  payable  to  "David  or
  104.        Sharleen Dunfield". If you choose not to order the  complete  MICRO-C
  105.        package, please discontinue using MICRO-C within thirty days.
  106.     
  107.           MICRO-C is provided on an "as is" basis, with no warranty  of  any
  108.        kind. In no event shall the author be liable for any damages  arising
  109.        from its use or distribution.
  110.     MICRO-C                                                          Page: 2
  111.  
  112.  
  113.        1.1 Code Portability
  114.     
  115.              With few exceptions, this compiler follows the  syntax  of  the
  116.           "standard" UNIX compiler (within  its  subset  of  the  language).
  117.           Programs written in MICRO-C should compile with few changes  under
  118.           other "standard" compilers.
  119.     
  120.           1.1.1 Unsupported Features:
  121.     
  122.                 MICRO-C does not currently support the following features of
  123.              standard 'C':
  124.     
  125.                     Long, Double, Float and Enumerated data types,
  126.                     Structures, Unions, Typedef and Bit fields.
  127.     
  128.           1.1.2 Additional Features
  129.     
  130.                 MICRO-C provides a few additional  features  which  are  not
  131.              always included in "standard" 'C' compilers:
  132.     
  133.                     Unsigned character variables, Nested comments, 16 bit
  134.                     character constants, Inline assembly code capability.
  135.     
  136.        1.2 Compiler Portability
  137.     
  138.              MICRO-C is written in standard 'C', and is capable of compiling
  139.           itself. This allows any system  with  a  'C'  compiler  (including
  140.           MICRO-C) to be used to port MICRO-C to another processor.
  141.     
  142.              The  parser  makes  very  few  assumptions  about  the   target
  143.           processor  or  operating  system  architecture,  allowing  a  code
  144.           generator  to  be  written  for  virtually   any   processor   and
  145.           environment.
  146.     
  147.              With the exception of required I/O routines (described  later),
  148.           the MICRO-C compiler uses no library functions, and relies  on  no
  149.           system services.
  150.     
  151.              Assuming that the code generator is fairly efficent,  and  that
  152.           the I/O routines and code generator are not unreasonably large,  a
  153.           full MICRO-C compiler may be implemented on systems with as little
  154.           as 32K of free ram and a single floppy disk.
  155.     MICRO-C                                                          Page: 3
  156.  
  157.  
  158.        1.3 The compiling process
  159.     
  160.              There are five  programs  which  work  together  to  completely
  161.           compile a MICRO-C program:
  162.     
  163.              The PREPROCESSOR (MCP) takes  the  original  'C'  source  file,
  164.           performs MACRO expansion and incorporates the contents of  INCLUDE
  165.           files  to  get  a  "pure"  'C'  output  file.  A   less   powerful
  166.           pre-processor is also contained inside the COMPILER, which  allows
  167.           this step to  be  skipped  for  programs  which  use  only  simple
  168.           pre-processor functions.
  169.     
  170.              The COMPILER  (MCC)  reads  a  file  containing  a  'C'  source
  171.           program, and translates it into an  equivalent  assembly  language
  172.           program.
  173.     
  174.              The OPTIMIZER (MCO) reads the assembly language output from the
  175.           compiler identifying and replacing "general" code produced by  the
  176.           compiler with more efficent code which is equivalent  in  specific
  177.           cases. This step is  optional,  allowing  you  to  choose  between
  178.           greater compile time and program efficency.
  179.     
  180.              The ASSEMBLER takes  the  assembly  language  produced  by  the
  181.           COMPILER or OPTIMIZER, and produces an OBJECT FILE which  contains
  182.           the executable code and external reference map for the program.
  183.     
  184.              The LINKER combines the executable code from  the  OBJECT  FILE
  185.           with code from  other  programs  which  it  calls  (including  any
  186.           LIBRARY functions), to produce a complete  stand-alone  executable
  187.           program.
  188.     
  189.              The ASSEMBLER and LINKER  are  NOT  included  as  part  of  the
  190.           MICRO-C package. These programs are  specific  to  the  particular
  191.           system, and must be obtained from the system vendor.
  192.     
  193.              Some cross ASSEMBLER's do  not  produce  an  object  file,  but
  194.           generate the executable program directly  instead.  These  systems
  195.           assume that the ENTIRE program is completely contained in a SINGLE
  196.           assembly language file. This type  of  system  prevents  you  from
  197.           using a object LIBRARY which is  an  integral  feature  of  any  C
  198.           programming system.
  199.     
  200.              To  accomodate  this  type  of  development   system,   without
  201.           sacrificing the ability to use a LIBRARY,  a  program  called  the
  202.           SOURCE LINKER (SLINK)  is  included  with  MICRO-C.  This  program
  203.           combines your program  with  library  functions  at  the  ASSEMBLY
  204.           LANGUAGE level, allowing the entire program code to  be  presented
  205.           to the assembler in a single file. See the section  entitled  "THE
  206.           SOURCE LINKER" for additional information.
  207.     MICRO-C                                                          Page: 4
  208.  
  209.  
  210.     2. THE COMMAND CO-ORDINATOR
  211.     
  212.           'CC' is a utility which co-ordinates  the  execution  of  programs
  213.        required for each step of the compilation process to provide a simple
  214.        "one step" compilation command. The basic MICRO-C package includes  a
  215.        version of  the  command  co-ordinator  which  handles  the  commands
  216.        necessary to compile for the 8086 processor (MCP, MCC86, MCO86, MASM,
  217.        LINK and EXE2BIN). This program  can  be  modified  as  necessary  to
  218.        handle other processors.
  219.     
  220.           NOTE: If you purchased MICRO-C as  part  of  a  "developers  kit",
  221.        refer to the documentation included with the CPU  support  files  for
  222.        details on using the pre-configured compiler for that particular CPU.
  223.     
  224.        2.1 The CC86 command
  225.     
  226.              The format of the 8086 'CC' command is:
  227.     
  228.                              CC86 <name> [options]
  229.     
  230.           2.1.1 Command line options
  231.     
  232.                 -a      - produce ASSEMBLER (.ASM) output file
  233.                 -k      - KEEP temporary files (do not delete)
  234.                 -l      - produce LINKABLE  (.OBJ) output file
  235.                 -o      - OPTIMIZE the output file (using MCO86)
  236.                 -p      - use the extended PRE-PROCESSOR (MCP)
  237.                 -q      - QUIET mode (suppress informational messages)
  238.                 -s      - produce SMALL-MODEL (.EXE) output file
  239.                 h=mcdir - specify MICRO-C home directory
  240.                 t=mctmp - specify prefix for TEMPORARY files
  241.     
  242.                 When  executing  the  sub-commands,  CC86  will  search  the
  243.              MICRO-C home directory, as well as any directories specified in
  244.              the 'PATH' environment variable. Libraries  are  accessed  from
  245.              the MICRO-C home directory only.
  246.     
  247.                 The environment variable 'MCDIR' is  examined  to  determine
  248.              the path to  the  MICRO-C  home  directory.  If  MCDIR  is  not
  249.              defined, CC86 will assume the string '\MC'.  You  may  override
  250.              this directory by using the 'h=' option on the command line.
  251.     
  252.                 Intermediate  results  from  each  command  are  stored   in
  253.              "temporary" files, which are fed as input to the next  command.
  254.              Temporary files will be deleted once they are no longer needed,
  255.              except in the case where a command fails.  When  this  happens,
  256.              any temporary file which  was  being  used  as  input  to  that
  257.              command will not be deleted, allowing you to examine it for the
  258.              cause of the error.
  259.     MICRO-C                                                          Page: 5
  260.  
  261.  
  262.                 The environment variable 'MCTMP' is examined to determine  a
  263.              prefix to prepend to temporary file  names.  If  MCTMP  is  not
  264.              defined, CC86 assumes  the  default  prefix  of  '$'.  You  may
  265.              override this prefix by using the 't=' option  on  the  command
  266.              line.
  267.     
  268.                 Here are example 'SET' commands suitable  for  inclusion  in
  269.              the AUTOEXEC.BAT file, of an IBM/PC based MICRO-C system  which
  270.              has the home directory in 'C:\MC', and a RAMDISK as drive 'D':
  271.     
  272.                     SET MCDIR=C:\MC
  273.                     SET MCTMP=D:\$
  274.     
  275.                 The '-p' option causes the extended pre-processor  (MCP)  to
  276.              be used. This provides greater pre-processor capability, at the
  277.              expense of longer compile time.
  278.     
  279.                 NOTE: If any compiler errors occur when using  this  option,
  280.              the line numbers contained in the error messages will refer  to
  281.              the temporary file containing the output from the pre-processor
  282.              ($<name>.CP). You must examine this file in order to  determine
  283.              the actual cause of the error.
  284.     
  285.                 The '-o' option causes the optimizer  (MCO86)  to  be  used,
  286.              which results in more efficent code, at the expense  of  longer
  287.              compile time.
  288.     
  289.                 The '-a' option causes CC86  to  bypass  the  assembler  and
  290.              linker, and produce an assembly source file (<name>.ASM) as the
  291.              output file.
  292.     
  293.                 The '-l' option causes CC86 to bypass the  link  stage,  and
  294.              produce a linkable object module  (<name>.OBJ)  as  the  output
  295.              file.
  296.     
  297.                 The '-s' option causes CC86 to link the  program  using  the
  298.              SMALL  memory  model,   and   produce   an   executable   image
  299.              (<name>.EXE) as the output file. This option  applies  only  to
  300.              those  processors  which  have  a  segmented  architecture  and
  301.              multiple memory models such as the 8086.
  302.     
  303.                 If none of '-a', '-l' or '-s' is specified, CC86  will  link
  304.              the program using the TINY memory model, and produce a  command
  305.              image (<name>.COM) as the output file.
  306.     MICRO-C                                                          Page: 6
  307.  
  308.  
  309.        2.2 Using multiple object modules
  310.     
  311.              The 'LC86' command takes one or more object modules produced by
  312.           'CC86' with the '-l' option, and links them with the libraries  to
  313.           produce an executable module. This module will be given  the  name
  314.           of the first file specified in the argument list.
  315.     
  316.              When compiling large programs which have more than  one  source
  317.           file, you must first compile all modules  using  'CC86'  with  the
  318.           '-l' option, and the use 'LC86' to link the resultant object files
  319.           into the final executable program.
  320.     
  321.              The '-s' option may be used as the  FIRST  argument,  to  cause
  322.           LC86 to link in the SMALL model.
  323.                 eg: CC86 FIRST -l
  324.                     CC86 SECOND -l
  325.                     LC86 FIRST SECOND           <-- TINY  Model
  326.                     LC86 -s FIRST SECOND        <-- SMALL Model
  327.     
  328.              The exact syntax  and  options  available  for  'CC'  and  'LC'
  329.           commands may differ in specific implementations of  the  compiler.
  330.           See the 'READ.ME' file and any additional technical  documentation
  331.           on your distribution disk(s) for details.
  332.     
  333.              NOTE: If you purchased MICRO-C as part of a  "developers  kit",
  334.           refer to the documentation included with the CPU support files for
  335.           details on using the pre-configured compiler for  that  particular
  336.           CPU.
  337.     MICRO-C                                                          Page: 7
  338.  
  339.  
  340.     3. THE MICRO-C PROGRAMMING LANGUAGE
  341.     
  342.           The following pages contain a brief summary of  the  features  and
  343.        constructs implemented in MICRO-C.
  344.     
  345.           This document does not  attempt  to  teach  'C'  programming,  and
  346.        assumes that the reader is familiar with the language.
  347.     
  348.        3.1 Constants
  349.     
  350.              The following forms of constants are supported by the compiler:
  351.     
  352.                 <num>       - Decimal number        (0 - 65535)
  353.                 0<num>      - Octal number          (0 - 0177777)
  354.                 0x<num>     - Hexidecimal number    (0x0 - 0xffff)
  355.                 '<char>'    - Character             (1 or 2 chars)
  356.                 "<string>"  - Address of literal string.
  357.     
  358.              The following "special" characters may be used within character
  359.           constants or strings:
  360.     
  361.                 \n          - Newline (line-feed)   (0x0a)
  362.                 \r          - Carriage Return       (0x0d)
  363.                 \t          - Tab                   (0x09)
  364.                 \f          - Formfeed              (0x0c)
  365.                 \b          - Backspace             (0x08)
  366.                 \<num>      - Octal value <num>     (Max. three digits)
  367.                 \x<num>     - Hex value <num>       (Max. two digits)
  368.                 \<char>     - Protect character <char> from input scanner.
  369.     
  370.        3.2 Symbols
  371.     
  372.              Symbol names  may  include  the  characters  'a'-'z',  'A'-'Z',
  373.           '0'-'9', and '_'. The characters '0'-'9' may not be  used  as  the
  374.           first character in the  symbol  name.  Symbol  names  may  be  any
  375.           length, however, only the first 15 characters are significant.
  376.     
  377.              The "char" modifier may be used to declare a symbol as an 8 bit
  378.           wide value, otherwise it is assumed to be 16 bits.
  379.     
  380.                               eg: char input_char;
  381.     
  382.              The "int" modifier may be used to declare a symbol as a 16  bit
  383.           wide value. This is assumed if neither "int" or "char" is given.
  384.     
  385.                                   eg: int abc;
  386.     
  387.              The "unsigned" modifier may be used to declare a symbol  as  an
  388.           unsigned positive only value. Note that unlike some 'C' compilers,
  389.           this modifier may be applied to a character (8 bit) variable.
  390.     
  391.                             eg: unsigned char count;
  392.     MICRO-C                                                          Page: 8
  393.  
  394.  
  395.              The "extern" modifier causes the compiler to be  aware  of  the
  396.           existance and  type  of  a  global  symbol,  but  not  generate  a
  397.           definition for that symbol. This allows the module being  compiled
  398.           to reference a symbol which is defined  in  another  module.  This
  399.           modifier may not be used with local symbols.
  400.     
  401.                             eg: extern char getc();
  402.     
  403.              A  symbol  declared  as  external  may  be  re-declared  as   a
  404.           non-external at a later  point  in  the  code,  in  which  case  a
  405.           definition for it will be generated. This allows  "extern"  to  be
  406.           used to inform the compiler of a function or variable type so that
  407.           it can be referenced  properly  before  that  symbol  is  actually
  408.           defined.
  409.     
  410.              The "static" modifier causes global variables to  be  available
  411.           only in the file where they are defined.  Variables  or  functions
  412.           declared  as  "static"  will  not  be   accessable   as   "extern"
  413.           declarations in other object files, nor will they cause  conflicts
  414.           with duplicate names in those files.
  415.     
  416.                          eg: static int variable_name;
  417.     
  418.              The "register" modifier indicates to the  code  generator  that
  419.           this is a high priority variable, and should be kept where  it  is
  420.           easy to get at. Since  its  interpretation  depends  on  the  code
  421.           generator, it is often  ignored  in  simple  implementations.  See
  422.           "Functions" for a  special  use  of  "register"  when  defining  a
  423.           function.
  424.     
  425.                           eg: register unsigned count;
  426.     
  427.              Symbols declared with a preceeding '*' are assumed to be 16 bit
  428.           pointers to the declared type.
  429.     
  430.                              eg: int *pointer_name;
  431.     
  432.              Symbol names declared followed by square brackets  are  assumed
  433.           to be arrays with a number of dimensions equal to  the  number  of
  434.           '[]' pairs that follow. The size of each dimension  is  identified
  435.           by a constant value  contained  within  the  corresponding  square
  436.           brackets.
  437.     
  438.                           eg: char array_name[5][10];
  439.     
  440.           3.2.1 More Symbol Examples
  441.     
  442.                 char a;                 /* 8 bit signed */
  443.                 unsigned char b;        /* 8 bit unsigned */
  444.                 int c;                  /* 16 bit signed */
  445.                 unsigned int d;         /* 16 bit unsigned */
  446.                 unsigned e;             /* also 16 bit unsigned */
  447.                 extern char f();        /* external function returning char */
  448.     MICRO-C                                                          Page: 9
  449.  
  450.  
  451.           3.2.2 Global Symbols
  452.     
  453.                 Symbols  declared  outside  of  a  function  definition  are
  454.              considered to  be  global  and  will  have  memory  permanently
  455.              reserved for them. Global symbols are defined by  name  in  the
  456.              output file, allowing other modules to access them.
  457.     
  458.                 Note that the compiler IS case  sensitive,  however  if  the
  459.              assembler you are using is NOT, you  must  be  careful  not  to
  460.              declare any global symbols with names that differ only in case.
  461.     
  462.                 All non-initialized global variables are  generated  at  the
  463.              very end of the output file, after the literal pool is  dumped.
  464.              Since non-initialized globals do not generate object code, this
  465.              allows them to be excluded from the image file when it is saved
  466.              to disk.
  467.     
  468.                 Global variables may be initialized with one or more values,
  469.              which are expressed as a single array of  integers  REGUARDLESS
  470.              of the size and shape of the variable. If more than  one  value
  471.              is expressed, '{' and '}' must be used.
  472.     
  473.                    eg: int i = 10, j[2][2] = { 1, 2, 3, 4 };
  474.     
  475.                 When arrays are declared, a null dimension may  be  used  as
  476.              the dimension size, in which case the size of  the  array  will
  477.              default to the number of initialized values.
  478.     
  479.                          eg: int array[] = { 1, 2, 3 };
  480.     
  481.                 Initialized global variables are automatically saved  within
  482.              the code image,  insuring  that  the  initial  values  will  be
  483.              available at run time. Any non-initialized elements of an array
  484.              which has been partly initialized will be set to zero.
  485.     
  486.                 Non-initialized global variables are not preset in any  way,
  487.              and will be undefined at the beginning of program execution.
  488.     
  489.           3.2.3 Local Symbols
  490.     
  491.                 Symbols declared within a function definition are  allocated
  492.              on the stack, and  exist  only  during  the  execution  of  the
  493.              function.
  494.     
  495.                 To simplify the allocation and de-allocation of stack space,
  496.              all local symbols must be declared  at  the  beginning  of  the
  497.              function before any code producing statements are encountered.
  498.     
  499.                 MICRO-C does not support initialization of  local  variables
  500.              in the declaration statement. Since local variables have to  be
  501.              initialized every time the function is entered, you can get the
  502.              same effect using assignment statements at the beginning of the
  503.              function.
  504.     
  505.                 No type is assumed for  arguments  to  functions.  Arguments
  506.              must be explicitly declared, otherwise they will  be  undefined
  507.              within the scope of the function definition.
  508.     MICRO-C                                                          Page: 10
  509.  
  510.  
  511.        3.3 Arrays & Pointers
  512.     
  513.              When MICRO-C passes an array to a function, it actually  passes
  514.           a POINTER to the array. References to arrays which  are  arguments
  515.           are automatically performed through the pointer.
  516.     
  517.              This allows the use of pointers and arrays to be interchangable
  518.           through the context of a function call. Ie: An array passed  to  a
  519.           function may be declared and used as  a  pointer,  and  a  pointer
  520.           passed to a function may be declared and used as an array.
  521.     
  522.        3.4 Functions
  523.     
  524.              Functions are  essentially  initialized  global  symbols  which
  525.           contain executable code.
  526.     
  527.              MICRO-C accepts  any  valid  value  as  a  function  reference,
  528.           allowing  some  rather  unique  (although  non-standard)  function
  529.           calls.
  530.     
  531.           For example:
  532.     
  533.                 function();     /* call function */
  534.                 variable();     /* call contents of a variable */
  535.                 (*var)();       /* call indirect through variable */
  536.                 (*var[x])();    /* call indirect through indexed array */
  537.                 0x5000();       /* call address 0x5000 */
  538.     
  539.              Since this is a single pass compiler, operands to functions are
  540.           evaluated and pushed on the stack in the order in which  they  are
  541.           encountered, leaving the last operand closest to the  top  of  the
  542.           stack. This is the opposite order from which  many  'C'  compilers
  543.           push operands.
  544.     
  545.              For functions with a fixed number of arguments,  the  order  of
  546.           which operands  are  passed  is  of  no  importance,  because  the
  547.           compiler looks after generating  the  proper  stack  addresses  to
  548.           reference variables.  HOWEVER,  functions  which  use  a  variable
  549.           number of arguments are affected for two reasons:
  550.     
  551.           1) The location of the LAST arguments are known (as fixed  offsets
  552.              from the stack pointer) instead of the FIRST.
  553.     
  554.           2) The symbols defined as arguments  in  the  function  definition
  555.              represent the LAST arguments instead of the FIRST.
  556.     
  557.              If a function is declared as "register", it  serves  a  special
  558.           purpose and causes the accumulator to be loaded with the number of
  559.           arguments passed whenever the function is called. This allows  the
  560.           function to know how many  arguments  were  passed  and  therefore
  561.           determine the location of the first argument.
  562.     MICRO-C                                                          Page: 11
  563.  
  564.  
  565.        3.5 Control Statements
  566.     
  567.              The following control statements are implemented in MICRO-C:
  568.     
  569.                 if(expression)
  570.                     statement;
  571.     
  572.                 if(expression)
  573.                     statement;
  574.                 else
  575.                     statement;
  576.     
  577.                 while(expression)
  578.                     statement;
  579.     
  580.                 do
  581.                     statement;
  582.                 while expression;
  583.     
  584.                 for(expression; expression; expression)
  585.                     statement;
  586.     
  587.                 return;
  588.     
  589.                 return expression;
  590.     
  591.                 break;
  592.     
  593.                 continue;
  594.     
  595.                 switch(expression) {
  596.                     case constant_expression :
  597.                         statement;
  598.                         ...
  599.                         break;
  600.                     case constant_expression :
  601.                         statement;
  602.                         ...
  603.                         break;
  604.                         .
  605.                         .
  606.                         .
  607.                     default:
  608.                         statement; }
  609.     
  610.                 label: statement;
  611.     
  612.                 goto label;
  613.     
  614.                 asm "...";
  615.     
  616.                 asm {
  617.                     ...
  618.                     }
  619.     MICRO-C                                                          Page: 12
  620.  
  621.  
  622.     3.5.1 Notes on Control Structures
  623.     
  624.         1)  Any "statement" may be a single statement or a compound
  625.             statement enclosed within '{' and '}'.
  626.     
  627.         2)  All three "expression"s in the "for" command are optional.
  628.     
  629.         3)  If a "case" selection does not end with "break;", it will
  630.             "fall through" and execute the following case as well.
  631.     
  632.         4)  Expressions following 'return' and 'do/while' do not have
  633.             to be contained in brackets (although this is permitted).
  634.     
  635.         5)  Label names may preceed any statement, and must be any
  636.             valid symbol name, followed IMMEDIATELY by ':' (No spaces
  637.             are allowed). Labels are considered LOCAL to a function
  638.             definition and will only be accessable within the scope
  639.             of that function.
  640.     
  641.         6)  The 'asm' statement used to implement the inline assembly
  642.             language capability of MICRO-C accepts two forms:
  643.                 asm "...";      <- Assemble single line.
  644.                 asm {           <- Assemble multiple lines.
  645.                     ...
  646.                     }
  647.     MICRO-C                                                          Page: 13
  648.  
  649.  
  650.        3.6 Expression Operators
  651.     
  652.              The following expression operators are implemented in MICRO-C:
  653.     
  654.     3.6.1 Unary Operators
  655.     
  656.         -           - Negate
  657.         ~           - Bitwise Complement
  658.         !           - Logical complement
  659.         ++          - Pre or Post increment
  660.         --          - Pre or post decrement
  661.         *           - Indirection
  662.         &           - Address of
  663.         sizeof      - Size of a object or type
  664.         (type)      - Typecast
  665.     
  666.     3.6.2 Binary Operators
  667.     
  668.         +           - Addition
  669.         -           - Subtraction
  670.         *           - Multiplication
  671.         /           - Division
  672.         %           - Modulus
  673.         &           - Bitwise AND
  674.         |           - Bitwise OR
  675.         ^           - Bitwise EXCLUSIVE OR
  676.         <<          - Shift left
  677.         >>          - Shift right
  678.         ==          - Test for equality
  679.         !=          - Test for inequality
  680.         >           - Test for greater than
  681.         <           - Test for less than
  682.         >=          - Test for greater than or equal to
  683.         <=          - Test for less than or equal to
  684.         &&          - Logical AND
  685.         ||          - Logical OR
  686.         =           - Assignment
  687.         +=          - Add to self assignment
  688.         -=          - Subtract from self assignment
  689.         *=          - Multiply by self assignment
  690.         /=          - Divide by and reassign assignment
  691.         %=          - Modular self assignment
  692.         &=          - AND with self assignment
  693.         |=          - OR with self assignment
  694.         ^=          - EXCLUSIVE OR with self assignment
  695.         <<=         - Shift left self assignment
  696.         >>=         - Shift right self assignment
  697.     MICRO-C                                                          Page: 14
  698.  
  699.  
  700.     NOTES:
  701.     
  702.         1)  The expression "a && b" returns 0 if "a" is zero, otherwise the
  703.             value of "b" is returned. The "b" operand is NOT evaluated if
  704.             "a" is zero.
  705.     
  706.         2)  The expression "a || b" returns the value of "a" if it is not 0,
  707.             otherwise the value of "b" is returned. The "b" operand is NOT
  708.             evaluated if "a" is non-zero.
  709.     
  710.     3.6.3 Other Operators
  711.     
  712.         ;           - Ends a statement.
  713.         ,           - Allows several expressions in one statement.
  714.                     + Separates symbol names in multiple declarations.
  715.                     + Separates constants in multi-value initialization.
  716.                     + Separates operands in function calls.
  717.         ?           - Conditional expression.
  718.         :           - Delimits labels, ends CASE and separates conditionals.
  719.         { }         - Defines a block of statements.
  720.         ( )         - Forces priority in expression, indicates function calls.
  721.         [ ]         - Indexes arrays. If fewer index values are given than the
  722.                       number of dimensions which are defined for the array,
  723.                       the value returned will be a pointer to the appropriate
  724.                       address.
  725.     
  726.                     Eg:
  727.                         char a[5][2];
  728.     
  729.                         a[3] returns address of forth row of two elements.
  730.                         (remember index's start from zero)
  731.     
  732.                         a[3][0] returns the character at index [3][0];
  733.     MICRO-C                                                          Page: 15
  734.  
  735.  
  736.        3.7 Inline Assembly Language
  737.     
  738.              Although 'C' is a powerful and  flexible  language,  there  are
  739.           sometimes instances where a particular operation must be  peformed
  740.           at the assembly language level. This most  often  involves  either
  741.           some processor feature for which there  is  no  corresponding  'C'
  742.           operation, or a section of very time critical code.
  743.     
  744.              MICRO-C provides access to assembly  language  with  the  'asm'
  745.           statement, which has two basic forms. The first is:
  746.     
  747.                                   asm "..." ;
  748.     
  749.              In this form, the entire  text  contained  between  the  double
  750.           quote characters (") is output as a single line to the  assembler.
  751.           Note that a  semicolon  is  required,  just  like  any  other  'C'
  752.           statement.
  753.     
  754.              Since this is a standard 'C' string, you can  use  any  of  the
  755.           "special" characters, and thus you could output multiple lines  by
  756.           using '\n' within the string. Another important characteristic  of
  757.           it being a string is that it will be protected from  pre-processor
  758.           substitution.
  759.     
  760.              The second form of the 'asm' statement is:
  761.     
  762.                                      asm {
  763.                                       ...
  764.                                        }
  765.     
  766.              In this form, all lines between '{' and '}' are output  to  the
  767.           assembler. Any text following the opening '{' (on the  same  line)
  768.           is ignored. Due to  the  unknown  characteristics  of  the  inline
  769.           assembly code, the closing '}' will only be recognized when it  is
  770.           the first non-whitespace character on a line.
  771.     
  772.              The integral pre-processor will not perform substitution on the
  773.           inline assembly code, however  the  external  pre-processor  (MCP)
  774.           will substitute in this form. This allows you to  create  assembly
  775.           language "macros" using MCP, and have parameters substituted  into
  776.           them when they are expanded:
  777.     
  778.             /*
  779.              * This macro issues a 'SETB' instruction for its parameter
  780.              */
  781.             #define setbit(bit) asm {\
  782.                 SETB bit\
  783.             }
  784.     
  785.             /*
  786.              * This macro WILL NOT WORK, since the 'bit' operand to the SETB
  787.              * instruction is contained within a string and is therefore
  788.              * protected from substitution by the pre-processor
  789.              */
  790.             #define setbit(bit) asm " SETB bit";
  791.     MICRO-C                                                          Page: 16
  792.  
  793.  
  794.        3.8 Preprocessor Commands
  795.     
  796.              The  MICRO-C  compiler  supports  the  following  pre-processor
  797.           commands. These commands are recognized only if they occur at  the
  798.           beginning of the input line.
  799.     
  800.              NOTE:  This  describes  the  limited  pre-processor  which   is
  801.           integral to the  compiler,  see  also  the  section  on  the  more
  802.           powerful external processor (MCP).
  803.     
  804.           3.8.1 #define <name> <replacement_text>
  805.     
  806.                 The "#define" command allows a global name  to  be  defined,
  807.              which will be replaced with the indicated text whenever  it  is
  808.              encountered in the input file. This occurs prior to  processing
  809.              by the compiler.
  810.     
  811.           3.8.2 #include <filename>
  812.     
  813.                 This command causes the indicated file to be opened and read
  814.              in as the source  text.  When  the  end  of  the  new  file  is
  815.              encountered, processing will continue with the  line  following
  816.              "#include" in the original file.
  817.     
  818.           3.8.3 #ifdef <name>
  819.     
  820.                 Processes the following lines (up to #else or  #endif)  only
  821.              if the given name is defined.
  822.     
  823.           3.8.4 #ifndef <name>
  824.     
  825.                 Processes the following lines (up to #else or  #endif)  only
  826.              if the given name is NOT defined.
  827.     
  828.           3.8.5 #else
  829.     
  830.                 Processes the following lines (up to  #endif)  only  if  the
  831.              preceeding #ifdef or #ifndef was false.
  832.     
  833.           3.8.6 #endif
  834.     
  835.                 Terminates #ifdef and #ifndef
  836.     
  837.                 NOTE: The integral pre-processor does not support nesting of
  838.              the #ifdef and #idndef constructs. If you wish  to  nest  these
  839.              conditionals, you must use the external pre-processor (MCP).
  840.     MICRO-C                                                          Page: 17
  841.  
  842.  
  843.        3.9 Error Messages
  844.     
  845.              When MICRO-C detects an  error,  it  outputs  an  informational
  846.           message indicating the type of problem encountered.
  847.     
  848.              The error message is preceeded by the  line  number(s)  of  the
  849.           line containing the error in all files being processed.
  850.     
  851.                              eg: 5:3: Syntax error
  852.     
  853.              In the above example, the main input file "#included" a file at
  854.           line 5, and a syntax error was discovered in that file at line 3.
  855.     
  856.              The following error messages are produced by the compiler:
  857.     
  858.           3.9.1 Compilation aborted
  859.     
  860.                 The preceeding error was so severe than the compiler  cannot
  861.              proceed.
  862.     
  863.           3.9.2 Constant expression required
  864.     
  865.                 The compiler requires a constant  expression  which  can  be
  866.              evaluated at compile time (ie: no variables).
  867.     
  868.           3.9.3 Declaration must preceed code.
  869.     
  870.                 All local variables must be defined at the beginning of  the
  871.              function, before any code producing statements are processed.
  872.     
  873.           3.9.4 Dimension table exhausted
  874.     
  875.                 The compiler has encountered more  active  array  dimensions
  876.              than it can handle.
  877.     
  878.           3.9.5 Duplicate local: 'name'
  879.     
  880.                 You have declared the named  local  symbol  more  than  once
  881.              within the same function definition.
  882.     
  883.           3.9.6 Duplicate global: 'name'
  884.     
  885.                 You have declared the named global symbol more than once.
  886.     
  887.           3.9.7 Expected '<token>'
  888.     
  889.                 The compiler  was  expecting  the  given  token,  but  found
  890.              something else.
  891.     
  892.           3.9.8 Expression stack overflow
  893.     
  894.                 The compiler has found a more complicated expression than it
  895.              can handle. Check that it is of  correct  syntax,  and  if  so,
  896.              break it up into two simpler expressions.
  897.     MICRO-C                                                          Page: 18
  898.  
  899.  
  900.           3.9.9 Expression stack underflow
  901.     
  902.                 The compiler has made an error in  parsing  the  expression.
  903.              Check that it is of correct syntax.
  904.     
  905.           3.9.10 Illegal indirection
  906.     
  907.                 You have attempted to perform an indirect operation ('*'  or
  908.              '[]') on an entity which is not a pointer or array. This  error
  909.              will also result if you attempt to index  an  array  with  more
  910.              indices than it has dimensions.
  911.     
  912.           3.9.11 Illegal initialization
  913.     
  914.                 Local variables may not be initialized  in  the  declaration
  915.              statement. Use assignments at the  beginning  of  the  function
  916.              code to perform the initialization.
  917.     
  918.           3.9.12 Illegal nested function
  919.     
  920.                 You may not declare a  function  within  the  definition  of
  921.              another function.
  922.     
  923.           3.9.13 Improper #else/#endif
  924.     
  925.                 A #else or #endif statement is out of place.
  926.     
  927.           3.9.14 Inconsistant re-declaration: 'name'
  928.     
  929.                 You have attempted to redefine  the  named  external  symbol
  930.              with a type which does not match its previously declared type.
  931.     
  932.           3.9.15 Incorrect declaration
  933.     
  934.                 A statement occuring outside of a function definition is not
  935.              a valid declaration for a function or global variable.
  936.     
  937.           3.9.16 Invalid '&' operation
  938.     
  939.                 You have attempted to reference  the  address  of  something
  940.              that has no address. This error also occurs when you attempt to
  941.              take the address of an array without giving it a  full  set  of
  942.              indicies. Since the address is already returned in  this  case,
  943.              simply drop the '&'. (The error occurs because you  are  trying
  944.              to take the address of an address).
  945.     
  946.           3.9.17 Macro expansion too deep
  947.     
  948.                 The compiler has encountered a nested macro reference  which
  949.              is too deep to be resolved.
  950.     
  951.           3.9.18 Macro space exhausted
  952.     
  953.                 The compiler has encountered  more  macro  ("#define")  text
  954.              than it has room to store.
  955.     MICRO-C                                                          Page: 19
  956.  
  957.  
  958.           3.9.19 No active loop
  959.     
  960.                 A "continue" or "break" statement was  encountered  when  no
  961.              loop is active.
  962.     
  963.           3.9.20 No active switch
  964.     
  965.                 A "case" or "default"  statement  was  encountered  when  no
  966.              "switch" statement is active.
  967.     
  968.           3.9.21 Not an argument: 'name'
  969.     
  970.                 You have declared the named variable as an argument, but  it
  971.              does not appear in the argument list.
  972.     
  973.           3.9.22 Non-assignable
  974.     
  975.                 You have attempted an operation which results in  assignment
  976.              of a value to an entity which cannot be assigned. (eg: 1 = 2);
  977.     
  978.           3.9.23 Numeric constant required
  979.     
  980.                 The compiler requires a constant expression which returns  a
  981.              simple numeric value.
  982.     
  983.           3.9.24 String space exhausted
  984.     
  985.                 The compiler has encountered more literal  strings  than  it
  986.              has room store.
  987.     
  988.           3.9.25 Symbol table full
  989.     
  990.                 The compiler has encountered more symbol definitions than it
  991.              can handle.
  992.     
  993.           3.9.26 Syntax error
  994.     
  995.                 The statement shown does not follow syntax rules and  cannot
  996.              be parsed.
  997.     
  998.           3.9.27 Too many active cases
  999.     
  1000.                 The compiler has run out of space  for  storing  switch/case
  1001.              tables. Reduce the number of active "cases".
  1002.     
  1003.           3.9.28 Too many defines
  1004.     
  1005.                 The compiler has encountered more '#define' statements  than
  1006.              it can handle. Reduce the number of #defines.
  1007.     
  1008.           3.9.29 Too many errors
  1009.     
  1010.                 The compiler is aborting because of excessive errors.
  1011.     MICRO-C                                                          Page: 20
  1012.  
  1013.  
  1014.           3.9.30 Too many includes
  1015.     
  1016.                 The compiler has encountered more  nested  "#include"  files
  1017.              than it can handle.
  1018.     
  1019.           3.9.31 Too many initializers
  1020.     
  1021.                 You have specified more initialization values than there are
  1022.              locations in the global variable.
  1023.     
  1024.           3.9.32 Type clash
  1025.     
  1026.                 You  have  attempted  to  combine  values   which   are   of
  1027.              incompatible types.
  1028.     
  1029.           3.9.33 Unable to open: 'name'
  1030.     
  1031.                 A "#include" command specified the named file,  which  could
  1032.              not be opened.
  1033.     
  1034.           3.9.34 Undefined: 'name'
  1035.     
  1036.                 You have referenced a name which is not defined as  a  local
  1037.              or global symbol.
  1038.     
  1039.           3.9.35 Unreferenced: 'name'
  1040.     
  1041.                 The named  symbol  was  defined  as  a  local  symbol  in  a
  1042.              function, but was never used in that function. This error  will
  1043.              occur at the end of  the  function  definition  containing  the
  1044.              symbol declaration. It is only a warning, and  will  not  cause
  1045.              the compile to abort.
  1046.     
  1047.           3.9.36 Unresolved: 'name'
  1048.     
  1049.                 The named symbol was forward  referenced  (Such  as  a  GOTO
  1050.              label), and was never defined. This error will occur at the end
  1051.              of the function definition containing the reference.
  1052.     
  1053.           3.9.37 Unterminated conditional
  1054.     
  1055.                 The end of file was encountered  when  a  "#if"  or  "#else"
  1056.              conditional block was being processed.
  1057.     
  1058.           3.9.38 Unterminated function
  1059.     
  1060.                 The  end  of  the  file  was  encountered  when  a  function
  1061.              definition was still open.
  1062.     MICRO-C                                                          Page: 21
  1063.  
  1064.  
  1065.        3.10 Quirks
  1066.     
  1067.              In its effort to provide the maximum  amount  of  functionality
  1068.           with the minimum amount of code, MICRO-C  deviates  from  standard
  1069.           'C' in some areas. The following is a short summary of  the  major
  1070.           infractions and quirks:
  1071.     
  1072.              The operands to '#' commands are  parsed  based  on  separating
  1073.           spaces, and any portion of the line not required  is  ignored.  In
  1074.           particular, the '#define' command only accepts a definition up  to
  1075.           the next space or tab character.
  1076.     
  1077.             eg: #define APLUSONE A+1        <-- uses "A+1"
  1078.                 #define APLUSONE A +1       <-- uses "A"
  1079.     
  1080.              Comments are stripped by the token scanner, which occurs  AFTER
  1081.           the '#' commands are processed.
  1082.     
  1083.             eg: #define NULL    /* comment */   <-- uses "/*"
  1084.     
  1085.              Note that since comments can therefore be included in "#define"
  1086.           symbols, you can use "/**/" to simulate spaces between tokens.
  1087.     
  1088.             eg: #define BYTE unsigned/**/char
  1089.     
  1090.              Include filenames are not delimited by '""'  or  '<>'  and  are
  1091.           passed to the operating system exactly as entered.
  1092.     
  1093.             eg: #include \mc\stdio.h
  1094.     
  1095.              NOTE:  The  above  quirks  do  not  apply  when  the   external
  1096.           pre-processor (MCP) is used.
  1097.     
  1098.              The appearance of a variable name in the argument  list  for  a
  1099.           function  declaration  serves  only  to  identify  that  variables
  1100.           location on the stack. MICRO-C will not define the variable unless
  1101.           it is explicitly declared (between the argument list and the  main
  1102.           function body). In other words, all arguments to a  function  must
  1103.           be explicitly declared.
  1104.     
  1105.              MICRO-C is more  strict  about  its  handling  of  the  ADDRESS
  1106.           operator ('&') than most other compilers. It will produce an error
  1107.           message if you attempt to take the address of  a  value  which  is
  1108.           already a fixed address (such as an array name without a full  set
  1109.           of indicies). Since an address is already produced in such  cases,
  1110.           simply drop the '&'.
  1111.     
  1112.              The 'x' in '0x' and '\x' is accepted in lower case only.
  1113.     MICRO-C                                                          Page: 22
  1114.  
  1115.  
  1116.              When operating on pointers, MICRO-C only scales  the  increment
  1117.           (++), decrement (--) and index ([]) operations to account for  the
  1118.           size of the pointer:
  1119.     
  1120.             eg: char *cptr;     /* pointer to character */
  1121.                 int  *iptr;     /* pointer to integer */
  1122.                 ++cptr;         /* Advance one character */
  1123.                 ++iptr;         /* Advance one integer */
  1124.                 cptr[10];       /* Access the tenth character */
  1125.                 iptr[10];       /* Access the tenth integer */
  1126.                 cptr += 10;     /* Advance 10 characters */
  1127.                 iptr += 10;     /* Advance ONLY FIVE integers */
  1128.     
  1129.             NOTE: A portable way to advance "iptr" by integers is:
  1130.     
  1131.                 iptr = &iptr[10];   /* Advance 10 integers */
  1132.     
  1133.              The INDEXING operator '[]' is not commutative  in  MICRO-C.  In
  1134.           other words 'array[index]' cannot be expressed as 'index[array]'.
  1135.     
  1136.              MICRO-C does  not  support  "complex"  declarations  which  use
  1137.           brackets '()' for other than function parameters. These  are  most
  1138.           often used in establishing pointers to functions:
  1139.                     int (*a)();     /* Pointer to function returning INT */
  1140.                     (*a)();         /* Call address in 'a' */
  1141.     
  1142.              Since MICRO-C allows you to call any value by following it with
  1143.           '()', you can get  the  desired  effect  in  the  above  case,  by
  1144.           declaring 'a' as a simple pointer to int, and calling it with  the
  1145.           same syntax:
  1146.                     int *a;         /* Pointer to INT */
  1147.                     (*a)();         /* Call address in 'a' */
  1148.     
  1149.              MICRO-C will not output external  declarations  to  the  output
  1150.           file  for  any  variables  or  functions  which  are  declared  as
  1151.           "extern", unless that symbol is actually  referenced  in  the  'C'
  1152.           source code. This prevents "extern" declarations in system  header
  1153.           files (such as "stdio.h") which are used as  prototypes  for  some
  1154.           library functions from causing those functions to be  loaded  into
  1155.           the  object  file.  Therefore,  any  "extern"  symbols  which  are
  1156.           referenced only by inline assembly code must be  declared  in  the
  1157.           assembly code, not by the MICRO-C "extern" statement.
  1158.     MICRO-C                                                          Page: 23
  1159.  
  1160.  
  1161.              Unlike some  'C'  compilers,  MICRO-C  will  process  character
  1162.           expressions using only  BYTE  values.  Character  values  are  not
  1163.           promoted to INT unless there is  an  INT  value  involved  in  the
  1164.           expression. This results in much more efficent code  when  dealing
  1165.           with characters, particularily  on  small  processors  which  have
  1166.           limited 16 bit instructions. Consider the statement:
  1167.     
  1168.                                  return c + 1;
  1169.     
  1170.              On some compilers, this will sign extend the character variable
  1171.           'c' into an integer value, and then ADD an integer  1  and  return
  1172.           the  result.  MICRO-C  will  ADD  the  character  variable  and  a
  1173.           character 1, and then promote the result to INT  before  returning
  1174.           it (results of expressions as  operands  to  'return'  are  always
  1175.           promoted to int).
  1176.     
  1177.              Unfortunately, programs have been written  which  rely  on  the
  1178.           automatic promotion of characters to INTs to  work  properly.  The
  1179.           most common source of problems is code  which  attempts  to  treat
  1180.           CHAR variables as UNSIGNED values (many older  compilers  did  not
  1181.           support UNSIGNED CHAR). For example:
  1182.     
  1183.                                 return c & 255;
  1184.     
  1185.              In a compiler which always evaluates character  expressions  as
  1186.           INT, the above statement will extract the value of 'c' as positive
  1187.           integer ranging from 0 to 255.
  1188.     
  1189.              In MICRO-C, ANDing a character with 255  results  in  the  same
  1190.           character, which gets promoted to an integer  value  ranging  from
  1191.           -128 to 127. To force the promotion  within  the  expression,  you
  1192.           could CAST the variable to an INT:
  1193.     
  1194.                               return (int)c & 255;
  1195.     
  1196.              The same objective can be achieved  in  a  more  efficent  (and
  1197.           correct) manner by declaring the variable 'c' as UNSIGNED CHAR, or
  1198.           by CASTing the variable to an UNSIGNED value:
  1199.     
  1200.                               return (unsigned)c;
  1201.     
  1202.              Note that this is not only more clearly shows the intent of the
  1203.           programmer, but also results is more efficent code generated.
  1204.     MICRO-C                                                          Page: 24
  1205.  
  1206.  
  1207.              A related quirk arises because most processors do not support a
  1208.           simple efficent method for adding or subtracting a  SIGNED  8  bit
  1209.           quantity and a 16 bit quantity. The code generators supplied  with
  1210.           MICRO-C make the assumption that character values being  added  or
  1211.           subtracted to/from integers will contain only POSITIVE values, and
  1212.           thus use UNSIGNED  addition/subtraction.  This  allows  much  more
  1213.           efficent code to be generated, as the carry/borrow  from  the  low
  1214.           order byte of the operation is simply propagated to the high order
  1215.           byte of the result.
  1216.     
  1217.              For those rare instances where you do wish  to  add/subtract  a
  1218.           potentially negative character value to/from an int, you can force
  1219.           the expression to be performed  in  less  efficent  fully  16  bit
  1220.           arithmetic by casting the character to an int.
  1221.     
  1222.                 int i;
  1223.                 char c;
  1224.                 ...
  1225.                 i += c;         /* Very efficent... B should be positive */
  1226.                 i += (int)c;    /* Less efficent... B can be negative */
  1227.     MICRO-C                                                          Page: 25
  1228.  
  1229.  
  1230.     4. ADVANCED TOPICS
  1231.     
  1232.           This section provides information on the more advanced aspects  of
  1233.        MICRO-C, which  is  generally  not  needed  for  casual  use  of  the
  1234.        language.
  1235.     
  1236.        4.1 Conversion Rules
  1237.     
  1238.              MICRO-C keep track of the "type" of  each  value  used  in  all
  1239.           expressions. This type identifies certain characteristics  of  the
  1240.           value,  such  as   size   range   (8/16   bits),   numeric   scope
  1241.           (signed/unsigned), reference (value/pointer) etc.
  1242.     
  1243.              When an  operation  is  performed  on  two  values  which  have
  1244.           identical "types", MICRO-C assigns that same "type" to the result.
  1245.     
  1246.              When the  two  value  "types"  involved  in  an  operation  are
  1247.           different, MICRO-C calculates the "type" of the result  using  the
  1248.           following rules:
  1249.     
  1250.           4.1.1 Size range
  1251.     
  1252.                 If both values are  direct  (not  pointer)  references,  the
  1253.              result will be 8 bits only if  both  values  were  8  bits.  If
  1254.              either value was 16 bits, the result will be 16 bits.
  1255.     
  1256.                 If one value is a pointer, and  the  other  is  direct,  the
  1257.              result will be a pointer to the same size value as the original
  1258.              pointer.
  1259.     
  1260.                 If both values were pointers, the result will be  a  pointer
  1261.              to 16 bits only if both original  pointers  referenced  16  bit
  1262.              values. If either pointer referenced an 8 bit value, the result
  1263.              will reference an 8 bit value.
  1264.     
  1265.           4.1.2 Numeric Scope
  1266.     
  1267.                 The result of an expression is considered to be signed  only
  1268.              if both original values were signed. If  either  value  was  an
  1269.              unsigned value, the result is unsigned.
  1270.     
  1271.           4.1.3 Reference
  1272.     
  1273.                 If either of the original values was a pointer,  the  result
  1274.              will be a pointer.
  1275.     
  1276.              Note that this "calculated" result type  is  used  for  partial
  1277.           results within an expression. Whenever a symbol such as a variable
  1278.           or function is referenced, the type of that symbol is  taken  from
  1279.           its declaration, no matter what "type" of value  was  last  stored
  1280.           (variable) or returned (function).
  1281.     
  1282.              The TYPECAST  operation  may  be  used  to  override  the  type
  1283.           calculated for the result of an expression if necessary.
  1284.     MICRO-C                                                          Page: 26
  1285.  
  1286.  
  1287.        4.2 Assembly Language Interface
  1288.     
  1289.              Assembly language programs may be called from 'C' functions and
  1290.           vice versa. These programs may be in the form of  inline  assembly
  1291.           language statements in the 'C' source code, or  separately  linked
  1292.           modules.
  1293.     
  1294.              When MICRO-C calls any routine ('C'  or  assembler),  it  first
  1295.           pushes all arguments to the routine onto the processor  stack,  in
  1296.           the order in  which  they  occur  in  the  argument  list  to  the
  1297.           function. This means that the LAST argument  to  the  function  is
  1298.           LOWEST on the processor stack.
  1299.     
  1300.              Arguments are always pushed as 16 bit values. Character  values
  1301.           are extended to 16 bits, and arrays are passed as 16 bit  pointers
  1302.           to the array. (MICRO-C knows that arrays which are  arguments  are
  1303.           actually  pointers,  and  automatically  references  through   the
  1304.           pointer).
  1305.     
  1306.              After pushing the arguments, MICRO-C then generates  a  machine
  1307.           language subroutine  call,  thereby  executing  the  code  of  the
  1308.           routine.
  1309.     
  1310.              Since the compiler uses the ACCUMULATOR and INDEX REGISTER,  it
  1311.           will automatically save them (if necessary) during  processing  of
  1312.           the arguments to the function (even if no arguments are  present),
  1313.           and therefore these registers do not have to be preserved  by  the
  1314.           called routine.
  1315.     
  1316.              NOTE that any other  registers  used  by  the  code  generation
  1317.           routines (register variables etc) will not be  saved  by  MICRO-C,
  1318.           and should be preserved by called functions if their content is to
  1319.           be relied on between function calls.
  1320.     
  1321.              Once the called routine returns, the arguments are removed from
  1322.           the stack by the calling program. This usually consists of  simply
  1323.           adding the number of  bytes  pushed  as  arguments  to  the  stack
  1324.           pointer.
  1325.     
  1326.              When the called function executes, the first thing usually done
  1327.           is to push any registers which must be preserved, and  to  reserve
  1328.           space on the stack for any local variables which are required.  In
  1329.           some implementations, a "base" register may also be established to
  1330.           provide a stable reference to the local variables and arguments.
  1331.     
  1332.              It is the responsibility of the called function to  remove  any
  1333.           saved registers and local variable space from the stack before  it
  1334.           returns. If a value is to be returned to the calling  program,  it
  1335.           is expected to be in the ACCUMULATOR register.
  1336.     MICRO-C                                                          Page: 27
  1337.  
  1338.  
  1339.              Local variables in a  function  may  be  referenced  as  direct
  1340.           offsets from the "base" register or stack pointer.  Note  that  if
  1341.           the stack pointer is used, offsets must be adjusted for the number
  1342.           of bytes which are pushed and  popped  on  the  stack  during  the
  1343.           execution of the function.
  1344.     
  1345.              The address of a particular local variable is calculated as:
  1346.     
  1347.                                 "base register"
  1348.                                        -
  1349.                      (Size of all local variables in bytes)
  1350.                                        + 
  1351.                (size of all preceeding local variables in bytes)
  1352.     
  1353.                                     -- OR --
  1354.     
  1355.                                 "stack pointer"
  1356.                                        +
  1357.                    (# bytes pushed during function execution)
  1358.                                        +
  1359.                (size of all preceeding local variables in bytes)
  1360.     
  1361.              Arguments to a  function  may  also  be  referenced  as  direct
  1362.           offsets from the "base" register or stack  pointer,  in  much  the
  1363.           same way as local variables are.
  1364.     
  1365.              The address of a particular argument is calculated as:
  1366.     
  1367.                                 "base register"
  1368.                                        +
  1369.         (# bytes pushed at entry of function to preserve registers etc.)
  1370.                                        +
  1371.                  (Size of return address on stack (usually 2))
  1372.                                        +
  1373.                       (# arguments from LAST argument) * 2
  1374.     
  1375.                                     -- OR --
  1376.     
  1377.                                 "stack pointer"
  1378.                                        +
  1379.                    (# bytes pushed during function execution)
  1380.                                        +
  1381.                      (size of all local variables in bytes)
  1382.                                        +
  1383.         (# bytes pushed at entry of function to preserve registers etc.)
  1384.                                        +
  1385.                  (Size of return address on stack (usually 2))
  1386.                                        +
  1387.                       (# arguments from LAST argument) * 2
  1388.     
  1389.              NOTE: The (number of bytes pushed at entry of  function)  is  a
  1390.           function of the code generator,  and  depends  on  the  particular
  1391.           MICRO-C implementation. Examine  some  assembly  output  from  the
  1392.           compiler to determine the actual number on your system.
  1393.     MICRO-C                                                          Page: 28
  1394.  
  1395.  
  1396.              If a function has been declared  as  "register",  MICRO-C  will
  1397.           load the accumulator with  the  number  of  arguments  which  were
  1398.           passed, each time the function is called. This allows the function
  1399.           to determine the location of the first argument.
  1400.     
  1401.              The address of  the  first  argument  passed  to  a  "register"
  1402.           function may be calculated as:
  1403.     
  1404.                            (accumulator contents) * 2
  1405.                                        + 
  1406.                                 "base register"
  1407.                                        +
  1408.         (# bytes pushed at entry of function to preserve registers etc.)
  1409.                                        +
  1410.                  (Size of return address on stack (usually 2))
  1411.     
  1412.                                     -- OR --
  1413.     
  1414.                            (accumulator contents) * 2
  1415.                                        +
  1416.                                 "stack pointer"
  1417.                                        +
  1418.                    (# bytes pushed during function execution)
  1419.                                        +
  1420.                      (size of all local variables in bytes)
  1421.                                        +
  1422.         (# bytes pushed at entry of function to preserve registers etc.)
  1423.                                        +
  1424.                  (Size of return address on stack (usually 2))
  1425.     
  1426.              Global  variables  exist  at  absolute  addresses  and  may  be
  1427.           referenced directly by name from within assembler  programs.  Keep
  1428.           in mind however, that MICRO-C uses only the first 15 characters of
  1429.           a symbol's name. Also, many code generators will reduce  the  size
  1430.           of names even further, often using an algorithm  to  compress  the
  1431.           name rather than simply truncating it. For this reason,  it  is  a
  1432.           good idea to avoid using global symbol names which are longer than
  1433.           6 or 8 characters  if  they  are  to  be  referenced  from  within
  1434.           assembly language programs.
  1435.     MICRO-C                                                          Page: 29
  1436.  
  1437.  
  1438.        4.3 Compiling for ROM
  1439.     
  1440.              Assuming  the  code  generator   does   not   employ   "tricky"
  1441.           programming techniques such as self  modifying  code,  the  output
  1442.           from the compiler is entirely "clean", and may be placed  in  Read
  1443.           Only Memory (ROM).
  1444.     
  1445.              The compiler places all initialized  global  variables  in  the
  1446.           output file as part of the code image. When the program is  stored
  1447.           in ROM, those variables are also stored in ROM, and  will  not  be
  1448.           modifiable.
  1449.     
  1450.              When the program is to be placed in ROM, you may not initialize
  1451.           any variables which you intend to modify  later.  Those  variables
  1452.           must be explicitly initialized by code executed at  the  beginning
  1453.           of the program.
  1454.     
  1455.              Initialized variables which you do not intend to  modify  (such
  1456.           as tables etc.) may be initialized in the declaration, and will be
  1457.           permanently saved in the ROM as part of the static code image.
  1458.     
  1459.              The  processor  stack  pointer  must  be  set  up  before   any
  1460.           expressions are evaluated, or any function  calls  are  performed.
  1461.           One way to do this is with inline assembly statements at  the  top
  1462.           of the file.
  1463.     
  1464.              All non-initialized global variables must be  located  in  RAM.
  1465.           The compiler usually outputs all such variables at the very end of
  1466.           the compilation, just after dumping the literal pool.  The  global
  1467.           variables may be moved to RAM by  editing  the  output  file,  and
  1468.           placing an appropriate "ORG" statement at  the  beginning  of  the
  1469.           globals.
  1470.     
  1471.              You must also be sure to relocate the temporary location  which
  1472.           is defined in the startup code and runtime library  ("?temp"),  as
  1473.           well  as  any  global  variables  used  in  the  standard  library
  1474.           functions.
  1475.     
  1476.              If extensive compilation for ROM is being  performed,  you  may
  1477.           want to use a version of the compiler which uses  an  intermediate
  1478.           output file (see "PORTING THE COMPILER"). This allows  a  separate
  1479.           code generator to be customized for ROM applications,  which  will
  1480.           output the appropriate stack setup instructions (this can be  done
  1481.           in "def_module()"), and locate the global variables in  RAM  (this
  1482.           can be done at the end of "def_literal()").
  1483.     MICRO-C                                                          Page: 30
  1484.  
  1485.  
  1486.     5. THE MICRO-C COMPILER
  1487.     
  1488.           The heart of the MICRO-C programming environment is the  COMPILER.
  1489.        This program reads a  file  containing  a  'C'  source  program,  and
  1490.        translates it into an equivalent assembly language program.
  1491.     
  1492.           The compiler includes its  own  limited  pre-processor,  which  is
  1493.        suitable for  compiling  programs  requiring  only  non-parameterized
  1494.        MACRO substitution, simple INCLUDE file capability, and  single-level
  1495.        CONDITIONAL processing.
  1496.     
  1497.           NOTE: If you purchased MICRO-C as  part  of  a  "developers  kit",
  1498.        refer to the documentation included with the CPU  support  files  for
  1499.        details on using the pre-configured compiler for that particular CPU.
  1500.     
  1501.        5.1 The MCC command
  1502.     
  1503.              When  created  using  the  'io'  routines   supplied   on   the
  1504.           distribution disk, the format of the MICRO-C Compiler command line
  1505.           is:
  1506.     
  1507.                     MCC [input_file] [output_file] [options]
  1508.     
  1509.              [input_file] is the name of  the  source  file  containing  'C'
  1510.           statements to read. If no filenames are given, MCC will read  from
  1511.           standard input.
  1512.     
  1513.              [output_file] is the name of the file to  which  the  generated
  1514.           assembly language code is written. If less than two filenames  are
  1515.           specified, MCC will write to standard output.
  1516.     
  1517.           5.1.1 Command Line Options
  1518.     
  1519.                 -q      - Instructs MCC to be quiet, and not display the
  1520.                           startup message when it is executed.
  1521.     
  1522.                 Additional options or features may be available in  specific
  1523.              implementations of the compiler. See the READ.ME files and  any
  1524.              additional technical documentation on  the  distribution  disks
  1525.              for those implementations.
  1526.     MICRO-C                                                          Page: 31
  1527.  
  1528.  
  1529.     6. PORTING THE COMPILER
  1530.     
  1531.           There are two major goals to accomplish when porting  the  MICRO-C
  1532.        compiler to a new machine. The first is to make the compiler  run  in
  1533.        the new environment, and the second is to make it  produce  code  for
  1534.        that environment.
  1535.     
  1536.           These two goals do not always go hand in hand. For example, it may
  1537.        be desirable to implement a CROSS COMPILER which generates code for a
  1538.        different system from that on which it runs.
  1539.     
  1540.           The usual method of porting a compiler to system A when a  version
  1541.        of the compiler is already running on system B, is to first create  a
  1542.        compiler which runs on system B, producing code for  system  A.  This
  1543.        "new" compiler may then be used to create a compiler  which  runs  on
  1544.        system A.
  1545.     
  1546.           The compiler consists of a module "compile"  which  contains,  the
  1547.        main compiler, input scanner, regular expression parser,  and  symbol
  1548.        table management routines.  This  is  the  "static"  portion  of  the
  1549.        compiler which does not change in different implementations.
  1550.     
  1551.           To create a working compiler, the above module  must  be  compiled
  1552.        and linked with an "io" module and "code"  module.  The  "io"  module
  1553.        performs the necessary initialization and I/O to allow  the  compiler
  1554.        to run in a particular  environment  (goal  #1).  The  "code"  module
  1555.        generates  the  assembly  language  output  code  for  a   particular
  1556.        environment (goal #2).
  1557.     
  1558.           The compiler uses NO system library functions, and  relies  on  NO
  1559.        system services (other  than  those  used  by  the  "io"  and  "code"
  1560.        modules). This allows the compiler to  be  ported  to  virtually  any
  1561.        system.
  1562.     
  1563.           All fixed compiler  parameters  (such  as  table  sizes  etc)  are
  1564.        contained in the header file "compile.h".  When  porting  to  systems
  1565.        with very limited RAM (less than 64k), you may have to reduce some of
  1566.        these sizes in order to get it to fit.
  1567.     
  1568.           Two additional modules are provided with the  compiler.  The  file
  1569.        "intercg.c", may be linked into the compiler in  place  of  the  code
  1570.        generator, and writes a "generic" intermediate  file  which  contains
  1571.        the pseudo operation and type tokens (See Code Generator).  The  file
  1572.        "genasm.c", may be linked with the regular "io" and  "code"  routines
  1573.        to produce a utility program which reads the  intermediate  file  and
  1574.        produces the assembly language code for a specific processor.
  1575.     
  1576.           NOTE: If your system makes a distinction between TEXT  and  BINARY
  1577.        files, the "io.c" routines must be modified for each program so  that
  1578.        the intermediate file will be accessed  in  BINARY  mode.  All  other
  1579.        files are accessed as TEXT.
  1580.     MICRO-C                                                          Page: 32
  1581.  
  1582.  
  1583.           Although this "split" compiling approach is slower than the  usual
  1584.        mode of direct assembly  language  production,  it  provides  several
  1585.        useful capabilities:
  1586.     
  1587.        1) The amount of ram required to  run  the  "separate"  compiler  and
  1588.           genasm programs can be considerably less than required to run  the
  1589.           "stand alone" compiler.
  1590.     
  1591.        2) A single parser may be used to generate code  for  several  target
  1592.           systems, by simply running a different  version  of  the  "genasm"
  1593.           utility, which is customized for each target.
  1594.     
  1595.        3) Use of the intermediate file  allows  distribution  of  "portable"
  1596.           programs which may be processed by "genasm" for different  targets
  1597.           WITHOUT distribution of the source code.
  1598.     
  1599.        4) A program may be written which processes this  intermediate  file,
  1600.           and "optimizes" the code. Additional "pseudo operation" codes  may
  1601.           be added to the output file if the target processor is capable  of
  1602.           operations which  the  more  "generic"  MICRO-C  output  does  not
  1603.           utilize.
  1604.     
  1605.        6.1 The "io" module
  1606.     
  1607.              The "io" module required  by  the  compiler  must  contain  the
  1608.           following function definitions:
  1609.     
  1610.              The function "main()" is called by the  operating  system  when
  1611.           the MICRO-C compiler is executed. It is  responsable  for  parsing
  1612.           any parmeters and command qualifiers, opening the input and output
  1613.           files,  performing  any  other  initializations  that   might   be
  1614.           required, and then  invoking  the  function  "compile()"  with  no
  1615.           arguments. The "compile" function is internal to  the  "compile.c"
  1616.           module, and will never return. For UNIX and  other  systems  which
  1617.           support I/O redirection, "stdin" and "stdout" are often  used  for
  1618.           the input and output files.
  1619.     
  1620.              The function "terminate(rc)" is called when  the  compiler  has
  1621.           finished all processing and wishes to terminate. The value "rc" is
  1622.           a return code: 0 = Success, program compiled without error,  -1  =
  1623.           Compile was aborted due to severe errors, n  =  Compile  finished,
  1624.           but had 'n' errors.
  1625.     
  1626.              The function "put_chr(chr, flag)"  is  passed  a  character  to
  1627.           output, as well as a flag. The flag will always be zero  when  the
  1628.           character is being sent to the console terminal, or non-zero  when
  1629.           the character is to be written to the output file.
  1630.     
  1631.              The function "put_str(*ptr, flag)" is passed  a  pointer  to  a
  1632.           zero terminated string, which is to be written to the  console  or
  1633.           output file as determined by "flag".
  1634.     
  1635.              The function "put_num(number, flag)" is passed a 16 bit number,
  1636.           which is to be written in printable form to the console or  output
  1637.           file as determined by "flag".
  1638.     MICRO-C                                                          Page: 33
  1639.  
  1640.  
  1641.           6.1.1 Compiler only routines
  1642.     
  1643.                 The following I/O routines are required by the compiler, but
  1644.              not by the "genasm" program.
  1645.     
  1646.                 The function  "get_lin(*ptr)"  is  passed  a  pointer  to  a
  1647.              character array,  and  should  read  a  single  line  from  the
  1648.              currently  open  input  file  into  that  array.  The  manifest
  1649.              definition "LINE_SIZE", found in "compile.h"  may  be  used  to
  1650.              determine the maximum line length acceptable to  the  compiler.
  1651.              Return of a non-zero value indicates the end of file condition.
  1652.     
  1653.                 The  function  "f_open(*ptr)"  is  passed  a  pointer  to  a
  1654.              filename. The new file should be opened, and if successful, the
  1655.              old input file should remain open and be "stacked", so that  it
  1656.              can be later returned to. If the file was opened  successfully,
  1657.              a non-zero value should be returned. A zero value indicates  to
  1658.              the compiler that the file could not be opened.
  1659.     
  1660.                 The function "f_close()"  is  responsible  for  closing  the
  1661.              currently open input  file,  and  returning  to  the  "stacked"
  1662.              previously open one. It receives no parameters. Note:  multiple
  1663.              "opens" may  be  stacked  -  see  the  manifest  definition  of
  1664.              "INCL_DEPTH" in the "compile.h" file.
  1665.     
  1666.           6.1.2 Genasm only routines
  1667.     
  1668.                 The following  I/O  routine  is  required  by  the  "genasm"
  1669.              program, but not by the compiler.
  1670.     
  1671.                 The function "get_char()" must  return  a  single  character
  1672.              from the input file as a 16 bit number with  a  positive  value
  1673.              between 0 and 255. A '-1' is  returned  for  the  end  of  file
  1674.              condition.
  1675.     
  1676.           6.1.3 Notes on I/O module
  1677.     
  1678.              1) It is the responsibility of the "put" routines to  translate
  1679.                 the  NEWLINE  '\n'  (0x0a)  character  into  whatever   line
  1680.                 termination  character(s)  are  required   by   the   target
  1681.                 operating system.
  1682.     
  1683.              2) If unix "stdin"  and  "stdout"  are  not  used,  it  is  the
  1684.                 responsibility  of  "main"  to  display  appropriate   error
  1685.                 messages if the input or output files could not be opened.
  1686.     
  1687.                 Refer to  the  sample  "io"  modules  distributed  with  the
  1688.              compiler.
  1689.     MICRO-C                                                          Page: 34
  1690.  
  1691.  
  1692.        6.2 The "code" module
  1693.     
  1694.              In order to insure that MICRO-C is portable  to  virtually  any
  1695.           environment,  the  compiler  makes  few  assumptions   about   the
  1696.           processor or system software of  the  target  system.  The  "code"
  1697.           module is relied  on  to  produce  all  machine  instructions  and
  1698.           assembler directives written to the output file.
  1699.     
  1700.              The only two real "assumptions" made about the target processor
  1701.           are:
  1702.     
  1703.           1) It is assumed that the target processor  has  an  "accumulator"
  1704.              register in which all math operations are performed,  and  that
  1705.              the  lower  8  bits  of   this   register   may   be   accessed
  1706.              independantly.
  1707.     
  1708.           2) It is  assumed  that  the  target  processor  has  one  "index"
  1709.              register which may be loaded with a  16  bit  value,  and  that
  1710.              memory references may be made indirectly through this register.
  1711.     
  1712.              If the target processor does not support the above features, it
  1713.           may be possible to write a code generator for it using some  other
  1714.           features of the processor.
  1715.     
  1716.              For example, if an "index" register  does  not  exist,  it  may
  1717.           often be implemented using two bytes of reserved memory.
  1718.     
  1719.              The code  generation  module  required  by  the  compiler  must
  1720.           contain the following function definitions:
  1721.     
  1722.              The function "do_asm(*ptr)" is passed a pointer to a  character
  1723.           string, which it should  write  to  the  output  file  EXACTLY  as
  1724.           passed, followed by a '\n' NEWLINE  character.  This  function  is
  1725.           used to write inline assembly language statements directly to  the
  1726.           output file.
  1727.     
  1728.              The function "def_module()"  is  called  at  the  beginning  of
  1729.           compilation, before any other code generator functions are called.
  1730.           It is used to output any pre-amble needed by the assembler.
  1731.     
  1732.              The function "end_module()"  is  called  at  the  very  end  of
  1733.           compilation, and is the last code generator function called. It is
  1734.           used to output any post-amble needed by the assembler.
  1735.     
  1736.              The function "def_static(symbol)" is passed am index  into  the
  1737.           compiler symbol tables for a global variable, which is about to be
  1738.           initialized as static storage. The call to this function  will  be
  1739.           immediately followed by a call to "init_static" or "end_static".
  1740.     
  1741.              The "init_static(token, value,  word)"  function  is  passed  a
  1742.           token and value, with which it should initialize a single  element
  1743.           of static storage. The "word" flag will be non-zero if  the  value
  1744.           is a 16 bit element. Only the "constant" tokens  (NUMBER,  STRING,
  1745.           LABEL) need be handled by this routine.
  1746.     MICRO-C                                                          Page: 35
  1747.  
  1748.  
  1749.              The  "end_static()"  function  is  called  to   terminate   the
  1750.           definition of static storage.
  1751.     
  1752.              NOTE: "init_static"  should  not  rely  on  "def_static"  being
  1753.           called first,  since  it  is  also  called  immediately  following
  1754.           "def_label" to define "switch" tables (See "do_switch"). After the
  1755.           table  is  defined,  the  compiler  will  call  "end_static()"  to
  1756.           terminate the initialization and set up for the next.
  1757.     
  1758.              The function "def_global(symbol, size)" is called at the end of
  1759.           the compile, once for each non-static global  variable  which  was
  1760.           defined. The "size" paremeter indicates the  number  of  BYTES  of
  1761.           memory to be reserved for that variable.
  1762.     
  1763.              The function "def_extern(symbol)" is called at the end  of  the
  1764.           compile, once for each  non-resolved  external  symbol  which  was
  1765.           defined. This routine should examine the type of  the  symbol  and
  1766.           output the appriopriate assembler directives to  allow  it  to  be
  1767.           referenced in another module.
  1768.     
  1769.              The "def_func(symbol, size)"  routine  is  called  to  start  a
  1770.           function definition. The "symbol" parameter is an index  into  the
  1771.           compiler symbol tables for the function entry being  defined.  The
  1772.           "size" parameter indicates how many  bytes  of  memory  should  be
  1773.           allocated  on  the  stack  for  local  variables.  When   defining
  1774.           "register" functions, care must  be  taken  that  the  entry  code
  1775.           preserves the contents of the accumulator.
  1776.     
  1777.              The "end_func()" routine is  called  to  terminate  a  function
  1778.           definition.  It  should  remove  anything  placed  on  the   stack
  1779.           (including the local variable space allocated by "def_func"),  and
  1780.           terminate the function with a "return" instruction.
  1781.     
  1782.              The "def_label(label)" function is called whenever the compiler
  1783.           wants to generate a label in the output file. Each label generated
  1784.           by the compiler is identified by a 16 bit unsigned number.  It  is
  1785.           up to the code generator to generate a unique label  suitable  for
  1786.           the target assembler.
  1787.     
  1788.              The "def_literal(*ptr, size)" function is called at the end  of
  1789.           the  compile,  just  before  non-initialized  global  symbols  are
  1790.           generated. This routine is  given  a  pointer  to  the  compiler's
  1791.           "literal pool", which contains all the character strings  occuring
  1792.           during the compilation. The "size" parameter  indicates  how  many
  1793.           characters are in the pool. This pool must  be  generated  in  the
  1794.           output file as a string of byte constants.
  1795.     
  1796.              The "call(token, value,  type,  clean)"  function  is  used  to
  1797.           generate  a  machine  language  subroutine  call  to  the   entity
  1798.           indicated by the "token, value & type" parameters (See later). The
  1799.           "clean" parameter indicates how many entries were pushed onto  the
  1800.           stack as arguments, which should be removed following the function
  1801.           call.  Note:  Since  stack  entries  are   TWO   bytes   in   most
  1802.           implementations, the "clean" value must be multiplied  by  two  to
  1803.           get the actual number of bytes to be removed from the stack.
  1804.     MICRO-C                                                          Page: 36
  1805.  
  1806.  
  1807.              The function "jump(label,  ljmp)"  is  called  to  generate  an
  1808.           unconditional jump instruction to the indicated compiler generated
  1809.           label. The "ljmp" flag will be set to zero if the jump  references
  1810.           code within the same expression from which it  is  generated,  and
  1811.           non-zero if one or more statements may occur between the jump  and
  1812.           the destination label. This allows  the  code  generator  to  take
  1813.           advantage of "short" jumps if they are available on the target.
  1814.     
  1815.              The function "jump_if(cond, label, ljmp) is called to  generate
  1816.           a conditional jump to a compiler generated label. The "cond" value
  1817.           indicates the condition: FALSE = Jump if accumulator is zero, TRUE
  1818.           = jump if accumulator is non-zero. Remaining  parameters  are  the
  1819.           same as above.
  1820.     
  1821.              The function "do_switch(label)" is  passed  the  address  of  a
  1822.           "switch" table, which contains 16  bit  entries,  and  is  of  the
  1823.           following format:
  1824.     
  1825.                         label-1, value-1, label-2, value-2, ....
  1826.                         label-n, value-n, 0, default_label
  1827.     
  1828.              This routine should search the table for the value currently in
  1829.           the accumulator, and if found, it  should  proceed  to  the  label
  1830.           associated with that value. If the value is not found  before  the
  1831.           end of the table is encountered (identified by a  label  value  of
  1832.           zero), execution should  proceed  at  the  address  identified  by
  1833.           "default_label".
  1834.     
  1835.              The "index_ptr(token, value, type)"  routine  should  load  the
  1836.           index register with the value  of  the  entity  indicated  by  the
  1837.           "token, value & type" parameters. This will always  be  a  16  bit
  1838.           wide quantity.
  1839.     
  1840.              The "index_adr(token, value, type)"  routine  should  load  the
  1841.           index register with the 16 bit address of the  symbol  represented
  1842.           by "token, value & type".
  1843.     
  1844.              The routine "expand(type)" is called following  the  evaluation
  1845.           of expressions in "return" and "switch" statements, and is used to
  1846.           insure that the result is a 16 bit value.
  1847.     
  1848.              The routine "accop(oper, type)" is  called  to  perform  a  "no
  1849.           operand" operation on the accumulator. See "compile.h" for a  list
  1850.           of these operations. The "type" passed indicates the type of value
  1851.           expected as a result.
  1852.     
  1853.              The routine "accval(oper, rtype, token, value, type)" is called
  1854.           to perform a "one  operand"  operation  on  the  accumulator.  See
  1855.           "compile.h" for a list of these operations. "rtype" indicates  the
  1856.           type of value expected as a result. "token",  "value"  and  "type"
  1857.           indicate  the  location  and  type  of  operand  which  is   being
  1858.           processed.
  1859.     MICRO-C                                                          Page: 37
  1860.  
  1861.  
  1862.           6.2.1 Notes on code generation
  1863.     
  1864.                 The meaning of the individual bits  in  the  16  bit  "type"
  1865.              value which is passed to many of the code generation  routines,
  1866.              is documented in the "compile.h" file.
  1867.     
  1868.                 The meaning of "token"  is  documented  in  the  "compile.h"
  1869.              file. For  each  type  of  "token",  "value"  has  a  different
  1870.              meaning:
  1871.     
  1872.                 Token           Meaning of "value"
  1873.                 ----------------------------------------------------------
  1874.                 NUMBER          The numeric value of the constant.
  1875.                 STRING          The offset into the literal pool.
  1876.                 LABEL           The value of the compiler generated label.
  1877.                 SYMBOL          Index into global symbol tables.
  1878.                 All others      Undefined.
  1879.     
  1880.                 When token is a SYMBOL, the "value" passed is used to  index
  1881.              into the global symbol tables (contained within  the  "compile"
  1882.              module) to  determine  information  about  the  variable.  When
  1883.              "value" is  less  than  the  value  of  the  compiler  internal
  1884.              variable 'global_top', the symbol is GLOBAL,  otherwise  it  is
  1885.              LOCAL:
  1886.     
  1887.                 s_name[value]   - Name of symbol (up to SYMBOL_SIZE chars)
  1888.                 s_type[value]   - Type of symbol (bits defined in "compile.h").
  1889.                 s_index[value]  - Variable index:
  1890.                         Global:     Indicates symbol was the n'th one defined.
  1891.                         Local:      Stack offset from def_func.
  1892.                         Argument:   Stack offset from last argument pushed.
  1893.     
  1894.                 When calculating the stack offset for  ARGUMENTs,  you  must
  1895.              add the number of bytes placed on the stack when  the  function
  1896.              was called. This  includes  the  local  variables,  the  return
  1897.              address, and any other values that "def_func" might push.
  1898.     
  1899.                 There are two popular ways of  providing  addressability  to
  1900.              local variables:
  1901.     
  1902.                 If the processor has many registers, you can reserve one  as
  1903.              a "base" pointer, and point it at the top of the stack when the
  1904.              function  is  entered.  This  allows  local  variables  to   be
  1905.              referenced as negative offsets from that "base"  register,  and
  1906.              arguments to be referenced as positive offsets  from  it.  This
  1907.              approach also allows the stack to  be  restored  directly  from
  1908.              this base  register  when  the  function  terminates.  See  the
  1909.              section on assembly language interfacing.
  1910.     
  1911.                 Another approach is to have the  code  generator  "remember"
  1912.              exactly how many bytes have been pushed onto  the  stack  since
  1913.              "def_func", and adjust the offsets it generates  based  on  the
  1914.              stack contents. This has  the  advantage  of  not  tying  up  a
  1915.              register.
  1916.     MICRO-C                                                          Page: 38
  1917.  
  1918.  
  1919.                 If you intend to use the MICRO-C Source Linker (SLINK), then
  1920.              you have to insure that whatever variable you use to  reference
  1921.              the "literal pool" qualifies as a "compiler  generated"  label,
  1922.              allowing SLINK to adjust it when processing the  source  files.
  1923.              Compiler  generated  labels  normally  consist  of   a   single
  1924.              character (usually '?'), followed by a  decimal  number.  Since
  1925.              the compiler begins generating its labels with the  value  '1',
  1926.              you may safely use '0' as the literal pool variable (Ie: '?0').
  1927.     
  1928.                 It is the responsibility of the code generator to keep track
  1929.              of the validity  of  the  upper  8  bits  of  the  accumulator.
  1930.              Appropriate sign extension or clearing of  high  bits  must  be
  1931.              performed as necessary to convert signed and unsigned character
  1932.              values when 16 bit results when required.
  1933.     
  1934.                 To improve the effiency of conditional statements, the  code
  1935.              generator should keep track of the validity of the "zero"  flag
  1936.              in  the  processor's  condition  code  register,  and  generate
  1937.              appropriate  "test"  instructions  only  if  necessary  when  a
  1938.              conditional jump is compiled.
  1939.     
  1940.                 For  processors  not  supporting   operations   with   stack
  1941.              contents, the "ON_STACK" and "ION_STACK" tokens may implemented
  1942.              by first popping the top of the  stack  into  a  register.  The
  1943.              "ISTACK_TOP" token is a special case, because  the  address  on
  1944.              the top of the stack must  not  be  lost.  This  token  may  be
  1945.              efficiently implemented, because "ISTACK_TOP" is only used  for
  1946.              read/write operations to  a  stacked  calculated  address.  For
  1947.              example:
  1948.     
  1949.                             array1[i] += array2[i];
  1950.     
  1951.                 This statement calculates the address of "array1[i]" (in the
  1952.              index register). Since the "index" register is  again  used  in
  1953.              calculating the address of "array2[i]", the first "index"  will
  1954.              be placed on the stack. Once the contents  of  "array2[i]"  are
  1955.              retrieved, it  will  be  added  using  "ISTACK_TOP",  and  then
  1956.              re-stored using "ION_STACK".
  1957.     
  1958.                 The "ISTACK_TOP" token may  thus  pop  the  address  into  a
  1959.              register, and set a flag indicating to the code generator  that
  1960.              the next "ION_STACK" token  is  to  go  through  that  register
  1961.              rather than the top of the stack. Note that since an arithmetic
  1962.              operation may be performed between the two references, you must
  1963.              not use a register which is  modified  in  code  generated  for
  1964.              arithmetic operations.
  1965.     
  1966.                 Refer to the sample code  generators  distributed  with  the
  1967.              compiler.
  1968.     MICRO-C                                                          Page: 39
  1969.  
  1970.  
  1971.        6.3 The "compile" module
  1972.     
  1973.              The "compile" module  contains  the  main  statement  analyser,
  1974.           input  scanner,  expression  parser  and  symbol  table  managment
  1975.           routines for the MICRO-C compiler. This module is  common  to  all
  1976.           implementations, and should NOT require changes in most cases. The
  1977.           source code for this module is contained in the  "compile.c"  file
  1978.           on your distribution diskette, and may  be  examined  for  insight
  1979.           into the internal operation of the compiler.
  1980.     
  1981.              This module must be compiled and linked with your I/O and  code
  1982.           generation routines to  generate  a  complete  executable  MICRO-C
  1983.           compiler.
  1984.     
  1985.              To test your code generator,  the  file  "test.c"  is  provided
  1986.           which when compiled using the new compiler, performs a  number  of
  1987.           simple tests  to  verify  your  code  generator.  This  is  not  a
  1988.           comprehensive analysis, as  it  makes  no  assumptions  about  the
  1989.           processor, however, it provides a good indication that  your  code
  1990.           generator is on the right track.
  1991.     
  1992.              A number of fixed parameters to the  compiler  (such  as  table
  1993.           sizes etc.) are contained in the header file "compile.h". The most
  1994.           common reason for changing  these  parameters  is  to  reduce  the
  1995.           memory requirements, in order to get  MICRO-C  to  fit  into  very
  1996.           small systems.
  1997.     
  1998.              If any of the parameters in "compile.h" are to be changed,  you
  1999.           must  make  the  changes  BEFORE  compiling  any  of  the  modules
  2000.           (compile, io or codegen).
  2001.     
  2002.              The file  "tokens.h"  contains  symbolic  definitions  for  the
  2003.           tokens parsed by the  compiler,  the  text  of  which  is  in  the
  2004.           character array variable "tokens". If you make any changes to this
  2005.           token table, MAKE SURE that the contents of the "tokens"  variable
  2006.           and the "tokens.h" file agree, otherwise, you will end up  with  a
  2007.           compiler for a very strange language.
  2008.     
  2009.           6.3.1 **NOTE for 32 bit compiler users
  2010.     
  2011.                 COMPILE.C has one potential portability  problem  if  it  is
  2012.              compiled on a machine where  an  'int'  is  not  16  bits.  The
  2013.              routine "skip_comment()" uses a 16 bit 'int' to hold  the  last
  2014.              two characters from the source file, in order to test  for  the
  2015.              "/*" and "*/" sequences.
  2016.     
  2017.                 If an 'int' can contain more that TWO characters,  you  must
  2018.              modify this function so that only the last two  characters  are
  2019.              retained.
  2020.     MICRO-C                                                          Page: 40
  2021.  
  2022.  
  2023.        6.4 Porting without a compiler
  2024.     
  2025.              If you have the MICRO-C  distribution  files,  but  no  running
  2026.           compiler,  it  is  still  possible  to  port  MICRO-C,  using  the
  2027.           following steps:
  2028.     
  2029.           1) You must write the code generator and I/O routines  in  another
  2030.              language. Using assembly language is  preferable,  because  you
  2031.              can then follow the MICRO-C function calling  conventions  (See
  2032.              "Assembly Language Interface  under  "Advanced  Topics").  This
  2033.              allows you to use the same routines with the compiler later.
  2034.     
  2035.           2) The "genasm.c" program should then be re-written  in  the  same
  2036.              language as above. This should not be difficult, since it is  a
  2037.              fairly simple program.
  2038.     
  2039.           3) Link "genasm" with your code generator  and  I/O  routines,  to
  2040.              create the "genasm" utility which reads intermediate files  and
  2041.              produces assembly language output.
  2042.     
  2043.           4) The "intermediate"  file  for  the  main  "compile"  module  is
  2044.              provided in the file "compile.i". When this file  is  processed
  2045.              by "genasm", and the resultant file assembled,  you  will  have
  2046.              the "compile" module which may be  linked  with  the  "io"  and
  2047.              "code" modules to produce the final compiler.
  2048.     
  2049.        6.5 Porting without a linker
  2050.     
  2051.              It is possible to port MICRO-C using a system  which  does  not
  2052.           support a linker. To do this, you must concatinate all the  source
  2053.           files "compile.c", "code.c" and "io.c" into  one  large  file  (in
  2054.           that order), and compile them all as one program.
  2055.     
  2056.              When this is done, the ".h" include files need only be included
  2057.           once, and external definitions  of  variables  occuring  in  other
  2058.           source files should not  be  used.  The  source  programs  on  the
  2059.           distribution disk all contain conditional  compilation  statements
  2060.           (#ifndef), which only perform the necessary #include and  external
  2061.           definition statements when compiling as a single file.
  2062.     MICRO-C                                                          Page: 41
  2063.  
  2064.  
  2065.        6.6 Optimization Techniques
  2066.     
  2067.              The MICRO-C compiler performs the following machine independant
  2068.           optimizations of the output file:
  2069.     
  2070.           1) All constant expressions are evaluated  at  compile  time,  and
  2071.              expressed as a single constant value in the output code.
  2072.     
  2073.           2) Commutative operations may be reversed  to  take  advantage  of
  2074.              partial results  already  in  the  accumulator.  This  includes
  2075.              operations which have an equivalent reverse (ie: "a>(b-1)"  may
  2076.              become "(b-1)<a").
  2077.     
  2078.           3) Redundant jumps as a result of "return" or  "break"  statements
  2079.              are suppressed.
  2080.     
  2081.           4) The sense of jumps in conditional statements are  reversed  for
  2082.              logically negated expressions, code for '!' is  only  generated
  2083.              if the value returned by that operator is actually used.
  2084.     
  2085.           5) Jumps between code generated within  a  single  expression  are
  2086.              flagged as "short".
  2087.     
  2088.              Although the MICRO-C compiler produces fairly  reasonable  code
  2089.           for the  processor  model  it  uses,  that  model  is  necessarily
  2090.           limited, in order that it might fit a  large  number  of  physical
  2091.           targets. There are  several  simple  optimizations  which  may  be
  2092.           performed to further enhance the code generated by the compiler in
  2093.           a specific implementation.
  2094.     
  2095.           6.6.1 Register Usage
  2096.     
  2097.                 MICRO-C assumes a single accumulator,  and  a  single  index
  2098.              register.  Additional  terms  in  complicated  expressions  are
  2099.              handled by placing temporary results on  the  processor  stack,
  2100.              and re-using those registers. All data placed on the  stack  is
  2101.              accessed on a "last in - first out" basis.
  2102.     
  2103.                 If the target processor has a  full  compliment  of  general
  2104.              purpose registers, an optimization may be performed  by  simply
  2105.              selecting another general purpose register as  the  accumulator
  2106.              or index register instead of placing the value  on  the  stack.
  2107.              The code generator must  keep  track  of  the  order  in  which
  2108.              registers are selected, and which register represents the "top"
  2109.              of the stack. If the number  of  values  "pushed"  exceeds  the
  2110.              number of available registers, the "oldest" register should  be
  2111.              placed on the stack, thereby allowing it to be re-used.
  2112.     MICRO-C                                                          Page: 42
  2113.  
  2114.  
  2115.           6.6.2 Jump Optimization
  2116.     
  2117.                 Although MICRO-C identifies jumps to instructions which span
  2118.              more than one expression as "long",  often  the  addresses  are
  2119.              close enough together that short jumps may  actually  be  used.
  2120.              This optimization is particularily useful for  processors  such
  2121.              as the 8086, which does not support "long"  conditional  jumps,
  2122.              and therefore must simulate them with a short conditional  jump
  2123.              of the opposite sense around a long unconditional jump.
  2124.     
  2125.           6.6.3 Redundant Load Elimination
  2126.     
  2127.                 Since  MICRO-C  evaluates  and  processes   each   statement
  2128.              individually, it  does  not  carry  partial  results  from  one
  2129.              statement to another.
  2130.     
  2131.                 Consider the following statements:
  2132.     
  2133.                                  a = x;
  2134.                                  b = a + 1;
  2135.     
  2136.                 MICRO-C generates the code:
  2137.     
  2138.                                  LOAD x
  2139.                                  STORE a
  2140.                                  LOAD a
  2141.                                  ADD 1
  2142.                                  STORE b
  2143.     
  2144.                 An optimization may be performed  by  recognizing  that  the
  2145.              second "load" instruction is redundant, and can be  eliminated.
  2146.              Note: A more efficent (but less readable)  way  of  coding  the
  2147.              above statements which would result in the latter code  without
  2148.              optimization is:
  2149.     
  2150.                                  b = (a = x) + 1;
  2151.     MICRO-C                                                          Page: 43
  2152.  
  2153.  
  2154.           6.6.4 Peephole Optimization
  2155.     
  2156.                 Consider the statement:
  2157.     
  2158.                                  a = *++ptr;
  2159.     
  2160.                 MICRO-C generates the code:
  2161.     
  2162.                                  LOAD ptr
  2163.                                  INCREMENT
  2164.                                  STORE ptr
  2165.                                  MOVE ACCUMULATOR TO INDEX
  2166.                                  LOAD [INDEX]
  2167.                                  STORE a
  2168.     
  2169.                 For a processor supporting  a  rich  set  of  direct  memory
  2170.              addressing modes, the above sequence can be shortened to:
  2171.     
  2172.                                  INCREMENT_MEMORY ptr
  2173.                                  LOAD [ptr]
  2174.                                  STORE a
  2175.     
  2176.                 One of the most  successful  techniques  of  optimizing  the
  2177.              output code is also one of the simplest.  Known  as  "peephole"
  2178.              optimization, the method consists of keeping a  window  of  the
  2179.              last few instructions generated,  and  scanning  the  list  for
  2180.              known patterns every time a new instruction is added to it.
  2181.     
  2182.                 As long as the instructions in the list at  least  partially
  2183.              match one or more  of  the  "predefined"  patterns,  additional
  2184.              instructions are collected  until  either  a  complete  pattern
  2185.              match occurs, or all known patterns are eliminated.
  2186.     
  2187.                 If no matches occur, the "oldest" instruction is written  to
  2188.              the output file, and the next one  becomes  the  first  in  the
  2189.              "window".
  2190.     
  2191.                 Whenever a pattern is discovered, it is replaced  by  a  new
  2192.              series of instructions which perform the same function, but  in
  2193.              a more efficent manner.
  2194.     
  2195.                 The new instruction sequences  are  replaced  on  the  list,
  2196.              which may then be  again  scanned,  allowing  further  possible
  2197.              reductions to be discovered.
  2198.     
  2199.                 Handling of labels in the "window" and  their  corresponding
  2200.              placement in the output file must be carefully done,  in  order
  2201.              to preserve the "logical" context of the original code.
  2202.     MICRO-C                                                          Page: 44
  2203.  
  2204.  
  2205.     7. THE MICRO-C PREPROCESSOR
  2206.     
  2207.           The MICRO-C Preprocessor is a source code filter,  which  provides
  2208.        greater capabilities than the preprocessor which is integral  to  the
  2209.        MICRO-C compiler. It has been implemented as a  stand  alone  utility
  2210.        program which processes the source code before it is compiled.
  2211.     
  2212.           Due to the higher complexity of  this  preprocessor,  it  operates
  2213.        slightly slower than the the integral MICRO-C preprocessor.  This  is
  2214.        mainly due to the fact that it reads each line from the file and then
  2215.        copies it to a new line while performing the macro substitution. This
  2216.        is necessary since each macro may contain parameters  which  must  be
  2217.        replaced "on the fly" when it is referenced.
  2218.     
  2219.           The integral MICRO-C preprocessor is very FAST,  because  it  does
  2220.        not copy the input line. When it encounters a '#define'd  symbol,  it
  2221.        simply adjusts the input scanner pointer to point to  the  definition
  2222.        of that symbol.
  2223.     
  2224.           Keeping the extended preprocessor as a stand alone utility  allows
  2225.        you  to  choose  between  greater   MACRO   capability   and   faster
  2226.        compilation. It also allows the system to continue  to  run  on  very
  2227.        small hardware platforms.
  2228.     
  2229.           The additional capabilities of the extended preprocessor are:
  2230.     
  2231.             - Parameterized MACROs.
  2232.     
  2233.             - Multiple line MACRO's.
  2234.     
  2235.             - Nested conditionals.
  2236.     
  2237.             - Ability to undefine MACRO symbols.
  2238.     
  2239.             - Library reference in include file names.
  2240.     MICRO-C                                                          Page: 45
  2241.  
  2242.  
  2243.        7.1 The MCP command
  2244.     
  2245.              The format of the MICRO-C Preprocessor command line is:
  2246.     
  2247.                     MCP [input_file] [output_file] [options]
  2248.     
  2249.              [input_file] is the name of  the  source  file  containing  'C'
  2250.           statements to read. If no filenames are given, MCP will read  from
  2251.           standard input.
  2252.     
  2253.              [output_file] is the name of the file to  which  the  processed
  2254.           source code is written. If less than two filenames are  specified,
  2255.           MCP will write to standard output.
  2256.     
  2257.           7.1.1 Command Line Options
  2258.     
  2259.                 MCP accepts the following command line [options]:
  2260.     
  2261.                 -c      - Instructs MCP to keep comments from  the input
  2262.                           file (except for those in '#' statements which
  2263.                           are always removed). Normally, MCP will remove
  2264.                           all comments.
  2265.     
  2266.                 l=path  - Defines the directory path which will be taken
  2267.                           to reference  "library"  files when  '<>'  are
  2268.                           used around an  '#include'  file name.  Unless
  2269.                           otherwise specified, the path defaults to:
  2270.                                         '\mc'
  2271.     
  2272.                 -q      - Instructs MCP to be quiet, and not display the
  2273.                           startup message when it is executed.
  2274.     
  2275.         <name>=<text>   - Pre-defines a non-parameterized macro  of  the
  2276.                           specified <name> with the string value <text>.
  2277.     MICRO-C                                                          Page: 46
  2278.  
  2279.  
  2280.        7.2 Preprocesor Commands
  2281.     
  2282.              The following commands are recognized by the MCP utility,  only
  2283.           if they occur at the beginning of the source file line:
  2284.     
  2285.           7.2.1 #define <name>(parameters) <replacement text>
  2286.     
  2287.                 Defines a global macro name which will be replaced with  the
  2288.              indicated <replacement text> wherever it occurs in  the  source
  2289.              file.
  2290.     
  2291.                 Macro  names  may  be  any  length,  and  may  contain   the
  2292.              characters 'a'-'z', 'A'-'Z', '0'-'9' and '_'.  Names  must  not
  2293.              begin with the characters '0'-'9'.
  2294.     
  2295.                 If the macro name is IMMEDIATELY followed by a list of up to
  2296.              10 parameter names contained in brackets, those parameter names
  2297.              will be substituted with parameters passed to the macro when it
  2298.              is referenced. Parameter names follow the same rules  as  macro
  2299.              names.
  2300.     
  2301.                      eg: #define min(a, b) (a < b ? a : b)
  2302.     
  2303.                 If any spaces exist between the macro name and  the  opening
  2304.              '(', the macro will not be  parameterized,  and  all  following
  2305.              text (including '(' and ')') will be  entered  into  the  macro
  2306.              definition.
  2307.     
  2308.                 If the very last character of a  macro  definition  line  is
  2309.              '\', MCP will continue the definition with the next  line  (The
  2310.              '\' is not included). Pre-processor statements included as part
  2311.              of a macro definition will not be processed by MCP, but will be
  2312.              passed on and handled by the integral MICRO-C preprocessor.
  2313.     
  2314.           7.2.2 #undef <symbol>
  2315.     
  2316.                 Undefines the named macro symbol. further references to this
  2317.              symbol will not be replaced.
  2318.     
  2319.                 NOTE: With MCP, macro definitions operate on a STACK. IE: If
  2320.              you define a macro  symbol,  and  then  re-define  it  (without
  2321.              '#undef'ing it first), subsequently '#undef'ing it  will  cause
  2322.              it to revert to its  previous  definition.  A  second  '#undef'
  2323.              would then cause it to be completely undefined.
  2324.     MICRO-C                                                          Page: 47
  2325.  
  2326.  
  2327.           7.2.3 #forget <symbol>
  2328.     
  2329.                 Similar  to  '#undef',  except  that  the  symbol  and   ALL
  2330.              SUBSEQUENTLY DEFINED SYMBOLS will be undefined.
  2331.     
  2332.                 Useful for releasing any local symbols (used only  within  a
  2333.              single include file).
  2334.     
  2335.                 For example:
  2336.     
  2337.                         #define GLOBAL "xxx"    /* first global symbol */
  2338.                             ...                 /* more globals */
  2339.                         #define LOCAL   "xxx"   /* first local symbol */
  2340.                             ...                 /* more locals */
  2341.                         /* body of include file goes here */
  2342.                         #forget LOCAL           /* release locals */
  2343.     
  2344.           7.2.4 #ifdef <symbol>
  2345.     
  2346.                 Causes the following lines (up to '#else' of '#endif') to be
  2347.              processed and included in the source file  only  if  the  named
  2348.              symbol is defined as a macro.
  2349.     
  2350.           7.2.5 #ifndef <symbol>
  2351.     
  2352.                 Causes the following lines (up to '#else' of '#endif') to be
  2353.              processed and included in the source file  only  if  the  named
  2354.              symbol is NOT defined as a macro.
  2355.     
  2356.                 NOTE: '#ifdef/#ifndef#else/#endif' may be nested.
  2357.     
  2358.           7.2.6 #else
  2359.     
  2360.                 Toggles the state of the "if_flag", controlling  conditional
  2361.              processing. Only has effect in the highest level  of  suspended
  2362.              processing. IE: Nested conditionals will work properly.
  2363.     
  2364.                 If the previous  '#ifdef/#ifndef'  failed,  processing  will
  2365.              begin again following the '#else'.
  2366.     
  2367.                 If the previous '#ifdef/#ifndef' passed, processing will  be
  2368.              suspended until the '#endif' is encountered.
  2369.     
  2370.                 NOTE: Since '#else' acts as a toggle, it may be used outside
  2371.              of any '#ifdef/#ifndef' to unconditionally  suspend  processing
  2372.              up to '#endif'.
  2373.     
  2374.           7.2.7 #endif
  2375.     
  2376.                 Resets  the  "if_flag"  controlling  conditionals,   causing
  2377.              processing to resume. Only has effect in the highest  level  of
  2378.              suspended  processing.  IE:  Nested  conditionals   will   work
  2379.              properly.
  2380.     MICRO-C                                                          Page: 48
  2381.  
  2382.  
  2383.           7.2.8 #include <filename>
  2384.     
  2385.                 Causes MCP to open the named file and include  its  contents
  2386.              as part of the input source.
  2387.     
  2388.                 If the filename is contained within '"' characters, it  will
  2389.              be opened exactly as  specified,  and  (unless  it  contains  a
  2390.              directory path) will reference a file in the current directory.
  2391.     
  2392.                 If the filename is contained within the characters  '<'  and
  2393.              '>', it will be  prefixed  with  the  library  path  (See  'l='
  2394.              option), and will therefore reference a file  in  that  library
  2395.              directory. The default  library  directory  is  assumed  to  be
  2396.              '\mc'.
  2397.     
  2398.                 For example:
  2399.     
  2400.                         #include "header.h"     /* from current directory */
  2401.                         #include <stdio.h>      /* from library directory */
  2402.     MICRO-C                                                          Page: 49
  2403.  
  2404.  
  2405.        7.3 Error messages
  2406.     
  2407.              When MCP detects an error during processing of an include file,
  2408.           it displays an error message,  which  is  preceeded  by  the  line
  2409.           numbers of the files in which the error occurs. If  more  than  10
  2410.           errors are encountered, MCP will terminate.
  2411.     
  2412.              The following error messages are reported by MCP:
  2413.     
  2414.           7.3.1 Cannot open include file
  2415.     
  2416.                 A '#include' statement on the  indicated  line  specified  a
  2417.              file which could not be opened for reading.
  2418.     
  2419.           7.3.2 Invalid include file name
  2420.     
  2421.                 A '#include' statement on the  indicated  line  specified  a
  2422.              file  name  which  was  not  contained  within  '"'   or   '<>'
  2423.              characters.
  2424.     
  2425.           7.3.3 Invalid macro name
  2426.     
  2427.                 A '#define' statement on the indicated line contains a macro
  2428.              name which does not follow the name rules.
  2429.     
  2430.           7.3.4 Invalid macro parameter
  2431.     
  2432.                 A '#define' statement on the indicated line contains a macro
  2433.              parameter name which does not follow the name rules.
  2434.     
  2435.                 A reference to a macro does not have a proper ')'  character
  2436.              to terminate the parameter list.
  2437.     
  2438.           7.3.5 Too many errors
  2439.     
  2440.                 More  than  10  errors  has  been  encountered  and  MCP  is
  2441.              terminating.
  2442.     
  2443.           7.3.6 Too many macro definitions
  2444.     
  2445.                 MCP has encountered more '#define' statements  than  it  can
  2446.              handle.
  2447.     
  2448.           7.3.7 Too many macro parameters
  2449.     
  2450.                 A '#define' statement on the indicated line  specifies  more
  2451.              parameters to the macro than MCP can handle.
  2452.     
  2453.           7.3.8 Too many include files
  2454.     
  2455.                 MCP has encountered more nested '#include'  statements  than
  2456.              it can handle.
  2457.     MICRO-C                                                          Page: 50
  2458.  
  2459.  
  2460.           7.3.9 Undefined macro
  2461.     
  2462.                 A '#undef' or '#forget'  statement  on  the  indicated  line
  2463.              references a macro name which has not been defined.
  2464.     
  2465.           7.3.10 Unterminated comment
  2466.     
  2467.                 The END OF FILE has  been  encountered  while  processing  a
  2468.              comment.
  2469.     
  2470.           7.3.11 Unterminated string
  2471.     
  2472.                 A quoted string on the indicated line has no end.
  2473.     MICRO-C                                                          Page: 51
  2474.  
  2475.  
  2476.     8. THE MICRO-C OPTIMIZER
  2477.     
  2478.           The MICRO-C optimizer is an output code filter which examines  the
  2479.        assembly code produced by the compiler, recognizing known patterns of
  2480.        inefficent code (using the "peephole" technique), and  replaces  them
  2481.        with more optimal code  which  performs  the  same  function.  It  is
  2482.        entirely table driven, allowing it to be modified for  virtually  any
  2483.        processor.
  2484.     
  2485.           Due its many table lookup operations, the  optimizer  may  perform
  2486.        quite slowly when processing a large  file.  For  this  reason,  most
  2487.        people prefer not to optimize during the debugging of a program,  and
  2488.        utilize the optimizer only when creating the final copy.
  2489.     
  2490.           NOTE: If you purchased MICRO-C as  part  of  a  "developers  kit",
  2491.        refer to the documentation included with the CPU  support  files  for
  2492.        details on using the pre-configured compiler for that particular CPU.
  2493.     
  2494.        8.1 The MCO command
  2495.     
  2496.              The format of the MICRO-C Optimizer command line is:
  2497.     
  2498.                     MCO [input_file] [output_file] [options]
  2499.     
  2500.              [input_file] is the name of the source file containing assembly
  2501.           statements to read. If no filenames are given, MCO will read  from
  2502.           standard input.
  2503.     
  2504.              [output_file] is the name of the file to  which  the  optimized
  2505.           assembly  code  is  written.  If  less  than  two  filenames   are
  2506.           specified, MCO will write to standard output.
  2507.     
  2508.           8.1.1 Command Line Options
  2509.     
  2510.                 MCO accepts the following command line [options]:
  2511.     
  2512.                 -d      - Instructs MCO to produce a  'debug' display on
  2513.                           standard output showing the source code  which
  2514.                           it is removing and replacing in the input file.
  2515.                           NOTE: If you do not specify an explict  output
  2516.                                 file, you will get the debug  statements
  2517.                                 intermixed with the  optimized  code  on
  2518.                                 standard output.
  2519.     
  2520.                 -q      - Instructs MCO to be quiet, and not display the
  2521.                           startup message when it is executed.
  2522.     MICRO-C                                                          Page: 52
  2523.  
  2524.  
  2525.        8.2 Porting to a new processor
  2526.     
  2527.              The MICRO-C Optimizer is completely table driven, and should be
  2528.           fairly easy to port to a new processor.
  2529.     
  2530.              The peephole optimization table  is  called  'peep_table',  and
  2531.           consists of two  sequential  character  string  entries  for  each
  2532.           optimization.
  2533.     
  2534.              The first is the "take" entry, and  represents  an  instruction
  2535.           sequence which (if found) is to be removed from the  output  file.
  2536.           The second  is  the  "give"  entry,  and  defines  a  sequence  of
  2537.           instructions to be placed in the output file at that  point.  NOTE
  2538.           that due to the way the optimizer removes and replaces instruction
  2539.           in the circular "peephole" buffer, the instructions in the  "give"
  2540.           entry ARE CODED IN REVERSE ORDER.
  2541.     
  2542.              Characters in the "take" entry  with  the  high  bit  set  (eg:
  2543.           '\200','\201') are special characters which represent any variable
  2544.           string which may occur in the instruction sequence,  and  will  be
  2545.           replaced with the same string wherever that  character  occurs  in
  2546.           the "give" entry. If  the  same  special  character  (eg:  '\200')
  2547.           occurs more than once  in  the  "take"  entry,  the  corresponding
  2548.           strings must be exactly the same or else the entire sequence  will
  2549.           not be matched.
  2550.     
  2551.              The processor will stop scanning  a  variable  string  when  it
  2552.           encounters the character which  immediately  follows  the  special
  2553.           character in the "take" entry, or at the end of the input line.
  2554.     
  2555.              There are cases in which you may  not  want  the  optimizer  to
  2556.           further reduce code substitued for a particular  optimization.  In
  2557.           this case, simply include a single characer comment  in  the  GIVE
  2558.           entry, in such  a  position  as  to  prevent  the  optimizer  from
  2559.           recognizing any further TAKE entries.
  2560.     
  2561.              The  manifest  SYMBOLS  defines  how  many  different   special
  2562.           characters are allowed in a peephole entry. You must not  use  any
  2563.           special characters which have  a  value  greater  than  ('\200'  +
  2564.           SYMBOLS - 1).
  2565.     
  2566.              The highest special character  (ie:  '\207'  if  SYMBOLS=8)  is
  2567.           treated as a special case, and will only match strings  containing
  2568.           numeric digits. This allows  optimizations  to  be  defined  which
  2569.           match constant values only, and not symbol names.
  2570.     MICRO-C                                                          Page: 53
  2571.  
  2572.  
  2573.     9. THE MAKE UTILITY
  2574.     
  2575.           The MAKE utility provides a method of automating the  building  of
  2576.        larger programs consisting of more that one object module.  The  main
  2577.        benefit of MAKE is that it keeps track of the files that each  module
  2578.        is dependant on, and will rebuild a module if any of those files have
  2579.        been modified since  the  module  was  last  built.  This  frees  the
  2580.        programmer from  the  task  of  remembering  which  files  have  been
  2581.        changed, and the commands needed to rebuild the dependant modules.
  2582.     
  2583.        9.1 MAKEfiles
  2584.     
  2585.              To use MAKE, you must first create a MAKEFILE, which is a  text
  2586.           file containing entries for each module in the program. Each entry
  2587.           consists of a DEPENDANCY list, and a series of COMMANDS.
  2588.     
  2589.           9.1.1 MAKEfile Entries
  2590.     
  2591.                 A dependency list in MAKE is a line which contains the  name
  2592.              of the module, followed by a ':', followed by the names of  any
  2593.              files on which it depends. The module name MUST begin in column
  2594.              1.
  2595.     
  2596.                 When MAKE is invoked, it will process each dependancy  list,
  2597.              and  will  execute  any  following  commands  (up  to   another
  2598.              dependancy list) if (1) the module does not exist,  or  (2)  if
  2599.              any of the files to the right of the ':' have a timestamp which
  2600.              is later than that of the module. For example:
  2601.     
  2602.                 main.obj : main.c main.h \\mc\\stdio.h
  2603.                     \\mc\\mcc main.c main.asm
  2604.                     masm/ml main;
  2605.                     -del main.asm
  2606.     
  2607.                 In the above example, the  'main.obj'would  be  rebuilt  (by
  2608.              compiling and assembling 'main.c') if either it did not already
  2609.              exist, or any of 'main.c', 'main.h' or '\mc\stdio.h' was  found
  2610.              to have a later timestamp.
  2611.     
  2612.                 The '-' preceeding the 'del' command prevents it from  being
  2613.              displayed. Unless the '-q' option is enabled, MAKE will display
  2614.              any commands not preceeded by '-' as they are executed.
  2615.     
  2616.                 NOTE: To enter a single '\' in the MAKEFILE,  you  must  use
  2617.              '\\', this is because like 'C',  MAKE  uses  '\'  to  "protect"
  2618.              special  characters  which  otherwise  are  used  for   special
  2619.              functions (such as '\', '$' and '#'). The first '\'  "protects"
  2620.              the second one, allowing it to pass through as source text.
  2621.     MICRO-C                                                          Page: 54
  2622.  
  2623.  
  2624.           9.1.2 Macro Substitutions
  2625.     
  2626.                 Sometimes in a MAKEFILE, you have a single file or directory
  2627.              path that you use  over  and  over  again.  If  it  is  a  long
  2628.              directory path, this may  involve  a  lot  of  typing,  and  it
  2629.              becomes inconvenient to change that name (if you want to use  a
  2630.              different directory etc.) because it is repeated many times.
  2631.     
  2632.                 MAKE includes a MACRO facility, which allows you  to  define
  2633.              variable names which will be replaced with a text  string  when
  2634.              used in subsequent MAKEfile lines. Names are defined by placing
  2635.              them in the MAKEfile, followed by '=',  and  the  text  string.
  2636.              Macro names being defined MUST begin in  column  one,  and  may
  2637.              consist of the characters ('a'-'z', 'A'-'Z', '0'-'9', and '_').
  2638.     
  2639.                 Whenever MAKE encounters a '$' in the  file,  it  takes  the
  2640.              name immediately following, and performs the macro replacement:
  2641.     
  2642.                 mcdir = \\mc
  2643.                 main.obj : main.c main.h $mcdir\\stdio.h
  2644.                     $mcdir\\mcc main.c main.asm
  2645.                     masm/ml main;
  2646.                     del main.asm
  2647.     
  2648.     
  2649.                 When a macro name is immediately  followed  by  alphanumeric
  2650.              text, use a single '\' to  separate  it  from  the  text.  This
  2651.              "protects"  the  first  character  of  the  text   from   being
  2652.              interpreted as part of the macro name:
  2653.     
  2654.                 mcdir = \\mc\\
  2655.                 main.obj : main.c main.h $mcdir\stdio.h
  2656.                     $mcdir\mcc main.c main.asm
  2657.                     masm/ml main;
  2658.                     del main.asm
  2659.     
  2660.                 There  are  several  predefined  macro  symbols  which   are
  2661.              available:
  2662.     
  2663.     
  2664.                 $*      = The full name of the dependant module (name.type).
  2665.                 $@      = The name only of the dependant module.
  2666.                 $.      = The full name of each file in the dependancy list,
  2667.                           separated from each other by a single space.
  2668.                 $,      = The full name of each file in the dependancy list,
  2669.                           separated from each other by a single comma.
  2670.                 $:      = The name only of each file in the dependancy list,
  2671.                           separated from each other by a single space.
  2672.                 $;      = The name only of each file in the dependancy list,
  2673.                           separated from each other by a single comma.
  2674.     MICRO-C                                                          Page: 55
  2675.  
  2676.  
  2677.                 File names in the dependancy list which are preceeded by '-'
  2678.              will not be included in the '$. $, $: $;' macro expansions:
  2679.     
  2680.                 mcdir = \\mc
  2681.                 main.obj : main.c -main.h -$mcdir\\stdio.h
  2682.                     $mcdir\\mcc $. $@.ASM
  2683.                     masm/ml $@;
  2684.                     del $@.ASM
  2685.     
  2686.           9.1.3 MAKEfile Comments
  2687.     
  2688.                 Whenever MAKE encounters the '#' character in the  MAKEFILE,
  2689.              it treats the remainder of the line as a comment, and does  not
  2690.              process it:
  2691.     
  2692.                 # Define Directories
  2693.                 mcdir = \\mc
  2694.     
  2695.                 # Build the MAIN module
  2696.                 main.obj : main.c -main.h -$mcdir\\stdio.h  # Dependants
  2697.                     $mcdir\\mcc $. $@.ASM                   # Compile
  2698.                     masm/ml $@;                             # Assemble
  2699.                     del $@.ASM                              # Delete tmp
  2700.     
  2701.           9.1.4 Ordering the MAKEfile
  2702.     
  2703.                 MAKE processes the MAKEfile is sequential fashion, with  the
  2704.              entries near the top being processed before  the  entries  near
  2705.              the bottom. To insure that each module is built  properly,  any
  2706.              files appearing in the dependancy list for a module  which  are
  2707.              themselves dependant  on  other  files,  should  have  MAKEfile
  2708.              entries which occur BEFORE the entries for  the  modules  which
  2709.              are dependant on them:
  2710.     
  2711.                 # Define Directories
  2712.                 mcdir = \\mc
  2713.                 # Build the MAIN module
  2714.                 main.obj : main.c -main.h -$mcdir\\stdio.h
  2715.                     $mcdir\\mcc $. $@.ASM
  2716.                     masm/ml $@;
  2717.                     del $@.ASM
  2718.                 # Build the SUB module
  2719.                 sub.obj : sub.c -sub.h
  2720.                     $mcdir\\mcc $. $@.ASM
  2721.                     masm/ml $@;
  2722.                     del $@.ASM
  2723.                 # Bind the executable file
  2724.                 # NOTE: If either of the above modules is rebuilt,
  2725.                 #       this entry will be guarenteed to execute.
  2726.                 main.exe : main.obj sub.obj
  2727.                     LINK $:;
  2728.     MICRO-C                                                          Page: 56
  2729.  
  2730.  
  2731.        9.2 Directives
  2732.     
  2733.              Like 'C', MAKE recognizes several "directives" in the MAKEfile.
  2734.           These  directives  are  only  recognized  if  they  occur  at  the
  2735.           beginning of the input line:
  2736.     
  2737.           9.2.1 @include <filename>
  2738.     
  2739.                 This command causes the indicated file to be opened and read
  2740.              in as the source  text.  When  the  end  of  the  new  file  is
  2741.              encountered, processing will continue with the  line  following
  2742.              "@include" in the original MAKEfile.
  2743.     
  2744.           9.2.2 @ifdef <name>
  2745.     
  2746.                 Processes the following lines (up to @else of  @endif)  only
  2747.              if the given MACRO name is defined. NOTE: <name> should not  be
  2748.              preceeded by '$', otherwise its CONTENTS will be tested.
  2749.     
  2750.           9.2.3 @ifndef <name>
  2751.     
  2752.                 Processes the following lines (up to @else of  @endif)  only
  2753.              if the given MACRO name is NOT defined.
  2754.     
  2755.           9.2.4 @ifeq <word1> <word2>
  2756.     
  2757.                 Processes the following lines (up to @else of  @endif)  only
  2758.              if the following two words match exactly. This  is  useful  for
  2759.              testing the value of a defined MACRO symbol.
  2760.     
  2761.           9.2.5 @ifne <word1> <word2>
  2762.     
  2763.                 Processes the following lines (up to @else or  @endif)  only
  2764.              if the following two words do not match.
  2765.     
  2766.           9.2.6 @else
  2767.     
  2768.                 Processes the following lines (up to  @endif)  only  if  the
  2769.              preceeding @ifdef, @ifndef, @ifeq or @ifne was false.
  2770.     
  2771.           9.2.7 @endif
  2772.     
  2773.                 Terminates @ifdef, @ifndef, @ifeq and @ifne.
  2774.     
  2775.           9.2.8 @type <text>
  2776.     
  2777.                 Displays the following text.
  2778.     
  2779.           9.2.9 @abort [text]
  2780.     
  2781.                 Terminates MAKE with an 'Aborted!' message. Any text on  the
  2782.              remainder of the line will be appended to the message.
  2783.     MICRO-C                                                          Page: 57
  2784.  
  2785.  
  2786.        9.3 The MAKE command
  2787.     
  2788.              The format of the MAKE command line is:
  2789.     
  2790.                            MAKE [makefile] [options]
  2791.     
  2792.              [makefile] is the name of the MAKEfile to process. If  no  name
  2793.           is given, MAKE assumes the default name 'MAKEFILE'.
  2794.     
  2795.           9.3.1 Command Line Options
  2796.     
  2797.                 MAKE accepts the following command line [options]:
  2798.     
  2799.                 ?       - Causes MAKE to output a short summary  of  the
  2800.                           available command line options.
  2801.     
  2802.                 -d      - Instructs MAKE to operate in "debug" mode, and
  2803.                           display the commands which it  would  execute,
  2804.                           without actually executing them. This provides
  2805.                           a method of quickly testing the MAKEFILE.
  2806.     
  2807.                 -q      - Instructs MAKE to be quiet, and not display the
  2808.                           informational messages and commands executed as
  2809.                           it progresses.
  2810.     
  2811.         <name>=<text>   - Pre-defines a macro  of  the  specified  <name>
  2812.                           with the string value  <text>.  This  OVERRIDES
  2813.                           any definition within the MAKEfile,  which  may
  2814.                           be used to establish a "default" value.
  2815.     MICRO-C                                                          Page: 58
  2816.  
  2817.  
  2818.        9.4 The TOUCH command
  2819.     
  2820.              TOUCH is a small utility program which sets  the  timestamp  of
  2821.           one or more files to the current or  specified  time/date.  It  is
  2822.           useful as a  method  of  forcing  MAKE  to  recognize  a  file  as
  2823.           "changed", even when it has not.
  2824.     
  2825.              For example, if  you  had  decided  to  "undo"  several  recent
  2826.           changes by restoring a backup of 'main.c', the restored file  will
  2827.           probably have a timestamp which is  older  than  the  last  module
  2828.           which was built. In this case, MAKE would be unaware that the file
  2829.           has changed, and would therefore not rebuild the module.
  2830.     
  2831.              The TOUCH command could then be used to "update" the  timestamp
  2832.           of 'main.c' to the current time, causing MAKE to recognize it as a
  2833.           changed file.
  2834.     
  2835.                                   TOUCH main.c
  2836.     
  2837.              You could also use TOUCH to force rebuilding of several files:
  2838.     
  2839.                            TOUCH main.c sub1.c sub2.c
  2840.     
  2841.              Or even ALL '.C' files:
  2842.     
  2843.                                    TOUCH *.c
  2844.     
  2845.              TOUCH can also be used to set the timestamp of  a  file  to  an
  2846.           arbritrary value, this may be useful  to  PREVENT  a  change  from
  2847.           causing an update:
  2848.     
  2849.                          TOUCH main.c t=0:00 d=31/10/80
  2850.     
  2851.              NOTE: Use of the 't=' or 'd=' parameters to  TOUCH  allows  the
  2852.           possibility that a changed file  will  go  unnoticed.  CAUTION  is
  2853.           advised.
  2854.     
  2855.              The MSDOS  implementation  of  TOUCH  supports  '-h'  and  '-s'
  2856.           options, which cause it to set  the  timestamp  of  HIDDEN  and/or
  2857.           SYSTEM files. If these options are not used, TOUCH will not affect
  2858.           those types of files.
  2859.     MICRO-C                                                          Page: 59
  2860.  
  2861.  
  2862.     10. THE SOURCE LINKER
  2863.     
  2864.           Many small development environments have assemblers which  do  not
  2865.        directly support an object linker. This causes  a  problem  with  'C'
  2866.        development, because the library functions must be  included  in  the
  2867.        source code, with several drawbacks:
  2868.     
  2869.         1)  There is no way to automatically tell which library functions
  2870.             to include, therefore, you must do it manually.
  2871.     
  2872.         2)  'C' library functions must be  re-compiled every  time,  in
  2873.             order to avoid conflict between compiler generated labels.
  2874.     
  2875.           The MICRO-C Source Linker (SLINK) helps overcome  these  problems,
  2876.        by automatically  joining  previously  compiled  (assembly  language)
  2877.        source code from the library to your programs compiler  output.  Only
  2878.        those files containing  functions  which  you  reference  are  joined
  2879.        (Taking into consideration of course  any  functions  called  by  the
  2880.        included library functions etc...). As the files are joined, compiler
  2881.        generated labels are automatically adjusted to be unique within  each
  2882.        file.
  2883.     
  2884.        10.1 The SLINK Command
  2885.     
  2886.              The format of the SLINK command line is:
  2887.     
  2888.                    SLINK [input_file] [output_file] [options]
  2889.     
  2890.              [input_file] is the name of  the  source  file  containing  the
  2891.           compiler output from your program. If no filenames is given, SLINK
  2892.           will read from standard input.
  2893.     
  2894.              [output_file] is the name of  the  file  to  which  the  linked
  2895.           source code is written. If less  that  two  filenames  are  given,
  2896.           SLINK will write to standard output.
  2897.     
  2898.           10.1.1 Command line options
  2899.     
  2900.                 SLINK accepts the following command line [options]:
  2901.     
  2902.                 ?       - Display command line help summary.
  2903.     
  2904.                 i=name  - Specify name of the External Index File.
  2905.     
  2906.                 -l      - Instructs SLINK to list each library used.
  2907.     
  2908.                 l=path  - Identifies the directory path which will be
  2909.                           taken to reference "library" files. If not
  2910.                           specified, it defaults to: '\mc\slib'
  2911.     
  2912.                 p=char  - Identifies the PREFIX character for compiler
  2913.                           generated symbols. Defaults is '?'.
  2914.     
  2915.                 -q      - Inhibit display of the startup message.
  2916.     
  2917.                 t=string- Prefix to prepend to temporary filenames.
  2918.                           If not specified, default is "$".
  2919.     MICRO-C                                                          Page: 60
  2920.  
  2921.  
  2922.        10.2 The External Index File
  2923.     
  2924.              SLINK uses a special file from the library to  determine  which
  2925.           symbols are in which files. This  files  is  called  the  EXTERNAL
  2926.           INDEX FILE, and is  found  in  the  library  directory  (see  'l='
  2927.           option), under the name "EXTINDEX.LIB".
  2928.     
  2929.              This  file  contains  entries  which  cross-reference  external
  2930.           symbols to files. Each entry is as follows:
  2931.     
  2932.             1)  Any lines beginning with '<' contain the names of files
  2933.                 which are to be processed and included at the BEGINNING
  2934.                 of the program (Before your source file). This the best
  2935.                 way to include the startup code and any runtime library
  2936.                 routines which are required  at  all  times,  and  also
  2937.                 provides a method of initializing any segments used.
  2938.                     eg: <6809rl.asm
  2939.     
  2940.             2)  Any lines beginning with '^' contain the names of files
  2941.                 which are to be processed AFTER the program and library
  2942.                 source files, but BEFORE any  uninitialized  data areas
  2943.                 are output. This is the best way to set up the location
  2944.                 and storage class of the uninitialized data  if it does
  2945.                 not immediately follow the executable program code, and
  2946.                 also providing any postamble needed by the segments.
  2947.     
  2948.             3)  Any lines beginning with '>' contain the names of files
  2949.                 which are to be processed at the END  of  the  program,
  2950.                 after all other information is output. This is the best
  2951.                 way to define heap memory storage,  and  to provide any
  2952.                 post-amble needed by the assembler.
  2953.     
  2954.             4)  Any lines beginning with '-' contain the names of files
  2955.                 which are to  be  included  if  any  of  the  following
  2956.                 symbols  (Up to another '<', '^', '>', '-' or '$')  are
  2957.                 referenced.
  2958.                     eg: -printf.asm format.asm fgets.asm fget.asm
  2959.     
  2960.                 NOTE: In most cases, the library functions will contain
  2961.                 indications of any external references that they do, in
  2962.                 which case SLINK will automatically include those files
  2963.                 even of the names are not mentioned on the '-' line. In
  2964.                 the example above, the following would suffice:
  2965.                         -printf.asm
  2966.     
  2967.             5)  The names  of  each  symbol  which  may  be  referenced
  2968.                 externally must follow the '<', '^', '>' or  '-' entry.
  2969.                 Symbols must occur one per line,  with  no  leading  or
  2970.                 trailing spaces.
  2971.                     eg: printf
  2972.                         fprintf
  2973.                         sprintf
  2974.     MICRO-C                                                          Page: 61
  2975.  
  2976.  
  2977.             6)  A line beginning with '$' is used to define the pseudo-
  2978.                 opcode used by SLINK to reserve uninitialized  data  at
  2979.                 the end of the output file.  Only  one  line  beginning
  2980.                 with '$' should be entered into the EXTINDEX.LIB  file.
  2981.                 The remainder of this line, including all  spaces  etc.
  2982.                 is entered between each symbol name,  and  the  decimal
  2983.                 size (in bytes) which is written to the output file.
  2984.                     eg: '$ RMB '    <- Quotes are for clarity
  2985.     
  2986.             A complete example:
  2987.     
  2988.                     -printf.asm
  2989.                     printf
  2990.                     fprintf
  2991.                     sprintf
  2992.                     -scanf.asm
  2993.                     scanf
  2994.                     fscanf
  2995.                     sscanf
  2996.                     <PREFIX.asm
  2997.                     ^MIDDLE.ASM
  2998.                     >SUFFIX.ASM
  2999.                     $ RMB
  3000.     
  3001.             In summary, the output file is written from:
  3002.     
  3003.                 1 - The '<' (prefix) files              *
  3004.                 2 - The program source files            *\
  3005.                 3 - Library files referenced (if any)   * > See note
  3006.                 4 - Segments 1-9 from above ...         */
  3007.                 5 - The '^' (middle) files
  3008.                 6 - Segments 1-9 from middle files      * See note
  3009.                 7 - Uninitialized data definitions      (if any)
  3010.                 8 - The '>' (suffix) files
  3011.                 9 - Segments 1-9 from sufix file(s)     * See note
  3012.     
  3013.             * NOTE: If these files contain multiple segments (see later),
  3014.                     all segments are grouped and written  in  seguential
  3015.                     order. IE: Seg 0 from all files is written, followed
  3016.                     by Seg 1, etc.
  3017.     
  3018.        10.3 Multiple source files
  3019.     
  3020.              SLINK processes only one source  file,  and  resolves  external
  3021.           references only to the library files. This is because  the  public
  3022.           symbol information is available in the EXTINDEX.LIB  files,  which
  3023.           contains no entries for the user supplied programs.
  3024.     
  3025.              If you wish to use source code  linking  for  a  program  which
  3026.           contains multiple source files, use "#include" statements  at  the
  3027.           end of your main program to include all of the other parts into  a
  3028.           single source file.
  3029.     MICRO-C                                                          Page: 62
  3030.  
  3031.  
  3032.        10.4 Source file information
  3033.     
  3034.           10.4.1 SLINK Directives
  3035.     
  3036.                 SLINK interpretes several "directives" which may be inserted
  3037.              in the  input  source  files  to  control  the  source  linking
  3038.              process. These directives must be on a separate line, beginning
  3039.              in column 1, and must be in  uppercase.  They  are  removed  by
  3040.              SLINK during processing, and thus will not cause conflict  with
  3041.              the normal syntax used by your assembler.
  3042.     
  3043.                                    $SE:<0-9>
  3044.     
  3045.                 The '$SE' directive is used  by  SLINK  to  define  multiple
  3046.              output segments. Up to 10 segments are allowed, with segment  0
  3047.              being the default which  is  selected  when  a  file  is  first
  3048.              encountered.  Other  segments  (1-9)  when  selected  via  this
  3049.              directive are written to temporary files, and re-joined at  the
  3050.              end of processing in  sequential  order.  this  allows  you  to
  3051.              separate sections of the source file (such as initialized data,
  3052.              literal pool etc.) into distinct areas of memory.
  3053.     
  3054.                               $DD:<symbol> <size>
  3055.     
  3056.                 The '$DD' directive is used  to  define  uninitialized  data
  3057.              storage areas, which will be allocated by SLINK between the '^'
  3058.              (middle) and '>' (suffix) files. This allows  you  to  allocate
  3059.              unitialized data outside of the bounds of the executable image,
  3060.              and thus exclude it from being saved to disk. This  action  may
  3061.              be thought  of  as  an  additional  (11'th)  segment  which  is
  3062.              available for uninitialized data only,  and  which  avoids  the
  3063.              temporary file read/write overhead associated with use  of  the
  3064.              other segments. This directive  is  normally  placed  into  the
  3065.              source file by the "def_global" routine  in  the  MICRO-C  code
  3066.              generator.
  3067.     
  3068.                                   $EX:<symbol>
  3069.     
  3070.                 The '$EX' directuve is used by SLINK to identify any symbols
  3071.              which are externally referenced. Whenever a '$EX' directive  is
  3072.              found, SLINK  searches  the  EXTINDX.LIB  file  for  the  named
  3073.              symbol, and marks the corresponding files for inclusion in  the
  3074.              program. This directive is normally placed into the source file
  3075.              by the "def_extern" routine in the MICRO-C code generator.
  3076.     
  3077.                 If you  are  writing  assembly  language  programs  for  the
  3078.              library, be sure to  include  "$SE:<0-9>"  directives  for  any
  3079.              segments you wish to access, "$DD:<symbol>  <size>"  directives
  3080.              for  any  uninitialized  data  you  wish   to   allocate,   and
  3081.              "$EX:<symbol>" directives for any symbols which you  externally
  3082.              reference. If you wish to place an assembly language comment on
  3083.              the same line, make sure it is separated from the remainder  of
  3084.              the directive by at least one space or tab character.
  3085.     MICRO-C                                                          Page: 63
  3086.  
  3087.  
  3088.                 Also, note that '<' (prefix) files may contain "$SE",  "$DD"
  3089.              and "$EX" directives, '^' (middle) files may contain "$SE"  and
  3090.              "$DD" but not "$EX", and '>' (suffix) files may  only  contains
  3091.              "$SE" directives. Basically, the rule is that "$EX"  cannot  be
  3092.              used after the libraries are included and "$DD" cannot be  used
  3093.              after the uninitialized data is output. Since  the  middle  and
  3094.              suffix files  are  ALWAYS  included,  simply  insure  that  all
  3095.              external references and data declarations needed by any of them
  3096.              are performed in the '<' (prefix) file.
  3097.     
  3098.           10.4.2 Compiler generated labels
  3099.     
  3100.                 As it processes each source file, SLINK scans each line  for
  3101.              symbols which consist of the '?' character (See  'p='  option),
  3102.              followed by a number. If it finds such as symbol, it inserts  a
  3103.              two character sequence ranging from 'AA' to  'ZZ'  between  the
  3104.              '?', and the number. This sequence will be incremented for each
  3105.              source file processed,  and  thus  insures  that  the  compiler
  3106.              generated symbols will be unique for each file.
  3107.     
  3108.                 If you  are  writing  assembly  language  programs  for  the
  3109.              library, you must be careful to  avoid  using  identical  local
  3110.              symbols in any of the library files, one way to do this  is  to
  3111.              use symbols which meet the above criteria.
  3112.     
  3113.        10.5 The SCONVERT command
  3114.     
  3115.              SCONVERT is a utility  which  assists  in  converting  existing
  3116.           assembly language  source  files  into  a  format  which  is  more
  3117.           suitable for use by the SLINK. Two main functions are performed:
  3118.     
  3119.           1) All comments are removed, and  all  spacing  is  reduced  to  a
  3120.              single space. This minimizes the size of the  file,  and  helps
  3121.              decrease linkage time.
  3122.     
  3123.           2) All symbols defined in the file which  are  not  identified  as
  3124.              "keep" symbols are converted to resemble the  MICRO-C  compiler
  3125.              generated symbols. This allows  SLINK  to  adjust  them  to  be
  3126.              unique within each source file.
  3127.     
  3128.              The format of the SCONVERT command line is:
  3129.     
  3130.     
  3131.                  SCONVERT [input_file] [output_file] [options]
  3132.     
  3133.              [input_file] is the name of  the  source  file  containing  the
  3134.           original assembly language program.  If  no  filenames  is  given,
  3135.           SCONVERT will read from standard input.
  3136.     
  3137.              [output_file] is the name of the file to  which  the  converted
  3138.           source code is written. If less  that  two  filenames  are  given,
  3139.           SCONVERT will write to standard output.
  3140.     MICRO-C                                                          Page: 64
  3141.  
  3142.  
  3143.           10.5.1 Command line options
  3144.     
  3145.                 SCONVERT accepts the following command line [options]:
  3146.     
  3147.                 ?       - Display command line help summary.
  3148.     
  3149.                 c=char  - Identifies the character used to begin a comment
  3150.                           at the trailing end of a source line. If no 'c='
  3151.                           is defined, SCONVERT will terminate processing at
  3152.                           the first blank or tab which follows the operand
  3153.                           field.
  3154.     
  3155.                 C=char  - Identifies the charcter which indicates a comment
  3156.                           line in the source code. Defaults to '*'.
  3157.     
  3158.                 k=name  - Identifies a symbol name to KEEP. This symbol will
  3159.                           not be converted. Multiple 'k=' are permitted.
  3160.     
  3161.                 K=file  - Identifies a file containing the names of symbols
  3162.                           to KEEP, one per line. Multiple 'K=' are permitted.
  3163.     
  3164.                 p=char  - Identifies the PREFIX character which is to be used
  3165.                           for the converted symbols. Defaults to '?'.
  3166.     
  3167.                 -q      - Instructs SCONVERT to be quiet, and not issue its
  3168.                           startup message.
  3169.     
  3170.                 SCONVERT identifies symbols in the input source file as  any
  3171.              string beginning with 'A-Z', 'a-z', '_' or '?', and  containing
  3172.              these charcters plus the digits '0-9'. If your assembler source
  3173.              files uses any other characters in its symbols, you must either
  3174.              edit your  sources  and  change  the  symbols,  or  modify  the
  3175.              'issymbol' function in the sconvert.c source file.
  3176.     
  3177.        10.6 The SINDEX command
  3178.     
  3179.              SINDEX is a utility  which  assists  in  the  creation  of  the
  3180.           EXTINDEX.LIB file used by SLINK. When you run SINDEX, it  examines
  3181.           all of the '.ASM' files in the current  directory,  and  writes  a
  3182.           EXTINDEX.LIB file which contains a '-' type entry for  each  file,
  3183.           and  external  symbol  entries  for  any  labels  which  it  finds
  3184.           conforming to the 'C' naming conventions (Starts with 'a-z', 'A-Z'
  3185.           or '_', and contains only 'a-z', 'A-Z', '0-9' or '_').
  3186.     
  3187.              Once  you  have  run  SINDEX,  you  must  manually   edit   the
  3188.           EXTINDEX.LIB file, and remove any file or symbol entries which you
  3189.           do not wish to have available as external references, as  well  as
  3190.           insert any necessary entries for '<', '^', '>' and '$' commands.
  3191.     
  3192.              NOTE: There is no information recorded in the  assembly  source
  3193.           file which indicates that a symbol was  declared  as  "static"  in
  3194.           'C'. For this reason, you must manually remove any  symbols  which
  3195.           you do not want to be accessable as external references,  EVEN  IF
  3196.           THEY WERE ORIGINALLY DECLARED AS "static" IN 'C'.
  3197.     MICRO-C                                                          Page: 65
  3198.  
  3199.  
  3200.           10.6.1 Command line options
  3201.     
  3202.                 SINDEX accepts the following command line options:
  3203.     
  3204.                 ?       - Display command line help summary.
  3205.     
  3206.                 i=name  - Specify name for index file to be written.
  3207.                           Dafault is "EXTINDEX.LIB".
  3208.     
  3209.                 You may also instruct SINDEX to search for  a  file  pattern
  3210.              other than '*.ASM' by passing it as a command line parameter.
  3211.     
  3212.                                 eg: SINDEX *.A86
  3213.     
  3214.        10.7 The SLIB command
  3215.     
  3216.              Once you have constructed your source  library,  you  may  from
  3217.           time to time want to make minor changes to it, either  adding  new
  3218.           functions, or removing old ones ones.
  3219.     
  3220.              You could make such changes simply by editing the  EXTINDEX.LIB
  3221.           file, however you would have to be very  careful  not  to  add  or
  3222.           delete the wrong entry, and you would have to  manually  determine
  3223.           if adding or removing the file would adversly affect the remainder
  3224.           of the library. For example, you could accidently add a  duplicate
  3225.           of another symbol name, or remove a symbol which is referred to by
  3226.           another file.
  3227.     
  3228.              To simplify maintenance of source libraries, you can  make  use
  3229.           of the "Source Librarian", a utility program which  automates  the
  3230.           addition and removal of source files, and automatically reports of
  3231.           any inconsistancies occuring in the source library.
  3232.     
  3233.              To use SLIB, you must first position yourself to the  directory
  3234.           containing the source library. And then  execute  SLIB  using  the
  3235.           command options described later to indicate the action to be taken
  3236.           on the library. If you do  not  specify  any  actions,  SLIB  will
  3237.           simply examine the library and report its size and content.
  3238.     
  3239.              You may use multiple command options in a single  SLIB  command
  3240.           if you wish to add and/or remove more than one file at a time.
  3241.     
  3242.              After  executing  any  command,  SLIB  will   report   on   any
  3243.           inconsistancies which it finds in the library. If any  are  found,
  3244.           and you have used a command which caused changes, SLIB will prompt
  3245.           for permission before writing the updated library file.
  3246.     MICRO-C                                                          Page: 66
  3247.  
  3248.  
  3249.           10.7.1 Command line options
  3250.     
  3251.                 The following options control the action(s)  which  will  be
  3252.              performed by SLIB on the source library index file.
  3253.     
  3254.                 ?       - Display command line help summary.
  3255.     
  3256.                 ?=file  - Display information about named source file.
  3257.     
  3258.                 a=file  - Add specified file as standard functions.
  3259.     
  3260.                 i=index - Use the specified INDEX file, if not specified,
  3261.                           the filename 'EXTINDEX.LIB' is assumed.
  3262.     
  3263.                 m=file  - Add named source file as a MIDDLE file.
  3264.     
  3265.                 p=file  - Add named source file as a PREFIX file.
  3266.     
  3267.                 -q      - Quiet mode: SLIB will not display informational
  3268.                           messages or ask for permission to update index.
  3269.     
  3270.                 r=file  - Remove the named file from the index.
  3271.     
  3272.                 s=file  - Add named source file as a SUFFIX file.
  3273.     
  3274.                 -w      - Write inhibit:  SLIB will not write the updated
  3275.                           library index.  This is useful if you just want
  3276.                           to see what would happen if you add or remove a
  3277.                           file.
  3278.     MICRO-C                                                          Page: 67
  3279.  
  3280.  
  3281.        10.8 Making a source library
  3282.     
  3283.              To make a complete source linkable library, follow these  basic
  3284.           steps:
  3285.     
  3286.           1) If you have assembly language library functions, run the SINDEX
  3287.              utility to create an index file with the names of  any  symbols
  3288.              defined in them. Edit this file and remove all names which  are
  3289.              LOCAL to the files. Only the global function and variable names
  3290.              should remain. NOTE: Also leave in any other symbols  or  names
  3291.              which you don't want changed by SCONVERT.
  3292.     
  3293.           2) Use SCONVERT to convert  the  assembly  language  sources  into
  3294.              library format, using the index file created above as your KEEP
  3295.              file (K=EXTINDEX.LIB). You may send the output  files  directly
  3296.              to your source library directory.
  3297.     
  3298.           3) Edit the converted assembly  language  sources  to  change  any
  3299.              declarations for uninitialized data into '$DD' directives,  and
  3300.              to add any '$SE' and '$EX' directives which may be needed.
  3301.     
  3302.           4) Compile all of your 'C' library functions to assembly language,
  3303.              using a code generator which outputs the appropriate directives
  3304.              for SLINK. Send the ASM output files  to  your  source  library
  3305.              directory.
  3306.     
  3307.           5) From within your library  directory,  run  the  SINDEX  utility
  3308.              again. This will create  an  index  file  (EXTINDEX.LIB)  which
  3309.              contains the names of all global symbols.
  3310.     
  3311.           6) Edit the index file and remove any non-public symbol names. You
  3312.              should also change the headers for the '<', '^' and '>'  files,
  3313.              and add the '$' record for reserved memory information.
  3314.     
  3315.           7) Run the SLIB utility, to check the new  library  for  duplicate
  3316.              symbols,  unresolved  external   references   and   any   other
  3317.              inconsistancies.
  3318.  
  3319.  
  3320.  
  3321.                                     MICRO-C
  3322.  
  3323.                                TABLE OF CONTENTS
  3324.  
  3325.  
  3326.                                                                          Page
  3327.  
  3328.      1. INTRODUCTION                                                        1
  3329.  
  3330.         1.1 Code Portability                                                2
  3331.         1.2 Compiler Portability                                            2
  3332.         1.3 The compiling process                                           3
  3333.  
  3334.      2. THE COMMAND CO-ORDINATOR                                            4
  3335.  
  3336.         2.1 The CC86 command                                                4
  3337.         2.2 Using multiple object modules                                   6
  3338.  
  3339.      3. THE MICRO-C PROGRAMMING LANGUAGE                                    7
  3340.  
  3341.         3.1 Constants                                                       7
  3342.         3.2 Symbols                                                         7
  3343.         3.3 Arrays & Pointers                                              10
  3344.         3.4 Functions                                                      10
  3345.         3.5 Control Statements                                             11
  3346.         3.6 Expression Operators                                           13
  3347.         3.7 Inline Assembly Language                                       15
  3348.         3.8 Preprocessor Commands                                          16
  3349.         3.9 Error Messages                                                 17
  3350.         3.10 Quirks                                                        21
  3351.  
  3352.      4. ADVANCED TOPICS                                                    25
  3353.  
  3354.         4.1 Conversion Rules                                               25
  3355.         4.2 Assembly Language Interface                                    26
  3356.         4.3 Compiling for ROM                                              29
  3357.  
  3358.      5. THE MICRO-C COMPILER                                               30
  3359.  
  3360.         5.1 The MCC command                                                30
  3361.  
  3362.      6. PORTING THE COMPILER                                               31
  3363.  
  3364.         6.1 The "io" module                                                32
  3365.         6.2 The "code" module                                              34
  3366.         6.3 The "compile" module                                           39
  3367.         6.4 Porting without a compiler                                     40
  3368.         6.5 Porting without a linker                                       40
  3369.         6.6 Optimization Techniques                                        41
  3370.  
  3371.      7. THE MICRO-C PREPROCESSOR                                           44
  3372.  
  3373.         7.1 The MCP command                                                45
  3374.         7.2 Preprocesor Commands                                           46
  3375.  
  3376.     MICRO-C                                                Table of Contents
  3377.  
  3378.                                                                          Page
  3379.         7.3 Error messages                                                 49
  3380.  
  3381.      8. THE MICRO-C OPTIMIZER                                              51
  3382.  
  3383.         8.1 The MCO command                                                51
  3384.         8.2 Porting to a new processor                                     52
  3385.  
  3386.      9. THE MAKE UTILITY                                                   53
  3387.  
  3388.         9.1 MAKEfiles                                                      53
  3389.         9.2 Directives                                                     56
  3390.         9.3 The MAKE command                                               57
  3391.         9.4 The TOUCH command                                              58
  3392.  
  3393.      10. THE SOURCE LINKER                                                 59
  3394.  
  3395.         10.1 The SLINK Command                                             59
  3396.         10.2 The External Index File                                       60
  3397.         10.3 Multiple source files                                         61
  3398.         10.4 Source file information                                       62
  3399.         10.5 The SCONVERT command                                          63
  3400.         10.6 The SINDEX command                                            64
  3401.         10.7 The SLIB command                                              65
  3402.         10.8 Making a source library                                       67
  3403.